From 3ba62ef1de77153e5a8c7bad4451b96f6a1678b0 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Sun, 12 Mar 2017 22:00:35 -0600 Subject: 8.10 --- zen/globals.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'zen/globals.h') diff --git a/zen/globals.h b/zen/globals.h index a1fd2764..b6c5dd28 100755 --- a/zen/globals.h +++ b/zen/globals.h @@ -18,7 +18,11 @@ template class Global { public: - Global() { static_assert(std::is_trivially_destructible::value, "this memory needs to live forever"); } + Global() + { + static_assert(std::is_trivially_destructible::value, "this memory needs to live forever"); + assert(!pod.inst && !pod.spinLock); //we depend on static zero-initialization! + } explicit Global(std::unique_ptr&& newInst) { set(std::move(newInst)); } ~Global() { set(nullptr); } @@ -50,9 +54,9 @@ private: //=> use trivially-destructible POD only!!! struct Pod { - std::shared_ptr* inst = nullptr; + std::shared_ptr* inst; // = nullptr; + std::atomic spinLock; // { false }; rely entirely on static zero-initialization! => avoid potential contention with worker thread during Global<> construction! //serialize access; can't use std::mutex: has non-trival destructor - std::atomic spinLock { false }; } pod; }; -- cgit