diff options
author | Daniel Wilhelm <shieldwed@outlook.com> | 2017-03-12 22:00:35 -0600 |
---|---|---|
committer | Daniel Wilhelm <shieldwed@outlook.com> | 2017-03-12 22:00:35 -0600 |
commit | 3ba62ef1de77153e5a8c7bad4451b96f6a1678b0 (patch) | |
tree | e6e69717e394a528a2e2aca3af036d4befaa9658 /zen/globals.h | |
parent | 8.9 (diff) | |
download | FreeFileSync-3ba62ef1de77153e5a8c7bad4451b96f6a1678b0.tar.gz FreeFileSync-3ba62ef1de77153e5a8c7bad4451b96f6a1678b0.tar.bz2 FreeFileSync-3ba62ef1de77153e5a8c7bad4451b96f6a1678b0.zip |
8.10
Diffstat (limited to 'zen/globals.h')
-rwxr-xr-x | zen/globals.h | 10 |
1 files changed, 7 insertions, 3 deletions
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 T> class Global
{
public:
- Global() { static_assert(std::is_trivially_destructible<Pod>::value, "this memory needs to live forever"); }
+ Global()
+ {
+ static_assert(std::is_trivially_destructible<Pod>::value, "this memory needs to live forever");
+ assert(!pod.inst && !pod.spinLock); //we depend on static zero-initialization!
+ }
explicit Global(std::unique_ptr<T>&& newInst) { set(std::move(newInst)); }
~Global() { set(nullptr); }
@@ -50,9 +54,9 @@ private: //=> use trivially-destructible POD only!!!
struct Pod
{
- std::shared_ptr<T>* inst = nullptr;
+ std::shared_ptr<T>* inst; // = nullptr;
+ std::atomic<bool> 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<bool> spinLock { false };
} pod;
};
|