summaryrefslogtreecommitdiff
path: root/zen/globals.h
diff options
context:
space:
mode:
Diffstat (limited to 'zen/globals.h')
-rw-r--r--zen/globals.h28
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
}
bgstack15