aboutsummaryrefslogtreecommitdiff
path: root/butl
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-12-16 16:08:06 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-12-16 16:08:06 +0200
commitbf57209f9e1c9f9f639c2d63c7674c3757750eb5 (patch)
tree77465a98ef25e6dd852fbe574007345a7a22c832 /butl
parentcc878f4e2b4bc6622742136dcb45e2ad912714f7 (diff)
Work around unexportable thread-local variables on Win32
Diffstat (limited to 'butl')
-rw-r--r--butl/diagnostics.cxx2
-rw-r--r--butl/utility18
-rw-r--r--butl/utility.cxx7
3 files changed, 21 insertions, 6 deletions
diff --git a/butl/diagnostics.cxx b/butl/diagnostics.cxx
index ad84810..9d74747 100644
--- a/butl/diagnostics.cxx
+++ b/butl/diagnostics.cxx
@@ -39,7 +39,7 @@ namespace butl
// mechanism in destructors, which is not a big deal, except for one
// place: exception_guard. Thus the ugly special check.
//
- if (!std::uncaught_exception () || exception_unwinding_dtor)
+ if (!std::uncaught_exception () || exception_unwinding_dtor ())
flush ();
#endif
}
diff --git a/butl/utility b/butl/utility
index 02d9331..b290153 100644
--- a/butl/utility
+++ b/butl/utility
@@ -188,14 +188,24 @@ namespace butl
// True means we are in the body of a destructor that is being called as
// part of the exception stack unwindining.
//
- LIBBUTL_EXPORT
extern
#ifdef BUTL_CXX11_THREAD_LOCAL
thread_local
#else
__thread
#endif
- bool exception_unwinding_dtor;
+ bool exception_unwinding_dtor_;
+
+ // On Windows one cannot export a thread-local variable so we have to
+ // use a wrapper functions.
+ //
+#ifdef _WIN32
+ LIBBUTL_EXPORT bool&
+ exception_unwinding_dtor ();
+#else
+ inline bool&
+ exception_unwinding_dtor () {return exception_unwinding_dtor_;}
+#endif
template <typename F>
struct exception_guard
@@ -205,9 +215,9 @@ namespace butl
{
if (std::uncaught_exception ())
{
- exception_unwinding_dtor = true;
+ exception_unwinding_dtor () = true;
f_ ();
- exception_unwinding_dtor = false;
+ exception_unwinding_dtor () = false;
}
}
diff --git a/butl/utility.cxx b/butl/utility.cxx
index 032d178..f64e7c8 100644
--- a/butl/utility.cxx
+++ b/butl/utility.cxx
@@ -12,6 +12,11 @@ namespace butl
#else
__thread
#endif
- bool exception_unwinding_dtor = false;
+ bool exception_unwinding_dtor_ = false;
+#endif
+
+#ifdef _WIN32
+ bool&
+ exception_unwinding_dtor () {return exception_unwinding_dtor_;}
#endif
}