From 7302bb4484d517a72cdffbd13ec7a9f2324cde01 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Sat, 29 Oct 2016 11:41:53 +0200 Subject: 8.6 --- zen/globals.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'zen/globals.h') 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 Global { public: - Global() { static_assert(std::is_trivially_destructible::value, "this memory needs to live forever"); } - explicit Global(std::unique_ptr&& newInst) { set(std::move(newInst)); } - ~Global() { set(nullptr); } - + Global() { static_assert(std::is_trivially_destructible::value, "this memory needs to live forever"); } + explicit Global(std::unique_ptr&& newInst) { set(std::move(newInst)); } + ~Global() { set(nullptr); } + std::shared_ptr 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::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* inst = nullptr; - //serialize access; can't use std::mutex: has non-trival destructor - std::atomic spinLock { false }; - } pod; + //avoid static destruction order fiasco: there may be accesses to "Global::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* inst = nullptr; + //serialize access; can't use std::mutex: has non-trival destructor + std::atomic 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 } -- cgit