diff options
-rw-r--r-- | butl/diagnostics.cxx | 2 | ||||
-rw-r--r-- | butl/utility | 18 | ||||
-rw-r--r-- | butl/utility.cxx | 7 |
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 } |