diff options
author | Daniel Wilhelm <shieldwed@outlook.com> | 2016-10-29 11:41:53 +0200 |
---|---|---|
committer | Daniel Wilhelm <shieldwed@outlook.com> | 2016-10-29 11:41:53 +0200 |
commit | 7302bb4484d517a72cdffbd13ec7a9f2324cde01 (patch) | |
tree | 17d2964c6768d49510206836a496fb1802a63e08 /zen/globals.h | |
parent | 8.5 (diff) | |
download | FreeFileSync-7302bb4484d517a72cdffbd13ec7a9f2324cde01.tar.gz FreeFileSync-7302bb4484d517a72cdffbd13ec7a9f2324cde01.tar.bz2 FreeFileSync-7302bb4484d517a72cdffbd13ec7a9f2324cde01.zip |
8.6
Diffstat (limited to 'zen/globals.h')
-rw-r--r-- | zen/globals.h | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/zen/globals.h b/zen/globals.h index ff8c890d..123028c7 100644 --- a/zen/globals.h +++ b/zen/globals.h @@ -18,10 +18,10 @@ template <class T> class Global { public: - Global() { static_assert(std::is_trivially_destructible<Pod>::value, "this memory needs to live forever"); } - explicit Global(std::unique_ptr<T>&& newInst) { set(std::move(newInst)); } - ~Global() { set(nullptr); } - + Global() { static_assert(std::is_trivially_destructible<Pod>::value, "this memory needs to live forever"); } + explicit Global(std::unique_ptr<T>&& newInst) { set(std::move(newInst)); } + ~Global() { set(nullptr); } + std::shared_ptr<T> get() //=> return std::shared_ptr to let instance life time be handled by caller (MT usage!) { while (pod.spinLock.exchange(true)) ; @@ -45,19 +45,19 @@ public: } private: - //avoid static destruction order fiasco: there may be accesses to "Global<T>::get()" during process shutdown - //e.g. _("") used by message in debug_minidump.cpp or by some detached thread assembling an error message! - //=> use trivially-destructible POD only!!! - struct Pod - { - std::shared_ptr<T>* inst = nullptr; - //serialize access; can't use std::mutex: has non-trival destructor - std::atomic<bool> spinLock { false }; - } pod; + //avoid static destruction order fiasco: there may be accesses to "Global<T>::get()" during process shutdown + //e.g. _("") used by message in debug_minidump.cpp or by some detached thread assembling an error message! + //=> use trivially-destructible POD only!!! + struct Pod + { + std::shared_ptr<T>* inst = nullptr; + //serialize access; can't use std::mutex: has non-trival destructor + std::atomic<bool> spinLock { false }; + } pod; }; #if defined _MSC_VER && _MSC_VER < 1900 -#error function scope static initialization is not yet thread-safe! + #error function scope static initialization is not yet thread-safe! #endif } |