From 43ebbb1c701dc7d49f950002bd5a18be781c8894 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 17 Sep 2013 17:58:21 -0700 Subject: [PATCH] Fix SharedSingleton to use memoryBarrier --- modules/beast_core/memory/SharedSingleton.h | 1 + modules/beast_core/memory/beast_Atomic.h | 9 +++------ modules/beast_core/threads/beast_Thread.cpp | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/beast_core/memory/SharedSingleton.h b/modules/beast_core/memory/SharedSingleton.h index 49fa2d3173..4e019cb0d8 100644 --- a/modules/beast_core/memory/SharedSingleton.h +++ b/modules/beast_core/memory/SharedSingleton.h @@ -92,6 +92,7 @@ public: bassert (lifetime == SingletonLifetime::createOnDemand || ! staticData.destructorCalled); staticData.instance = &staticData.object; new (staticData.instance) SharedSingleton (lifetime); + memoryBarrier(); instance = staticData.instance; } } diff --git a/modules/beast_core/memory/beast_Atomic.h b/modules/beast_core/memory/beast_Atomic.h index 9fcc92fcfa..7650da5794 100644 --- a/modules/beast_core/memory/beast_Atomic.h +++ b/modules/beast_core/memory/beast_Atomic.h @@ -131,9 +131,6 @@ public: */ Type compareAndSetValue (Type newValue, Type valueToCompare) noexcept; - /** Implements a memory read/write barrier. */ - static void memoryBarrier() noexcept; - //============================================================================== #if BEAST_64BIT BEAST_ALIGN (8) @@ -373,8 +370,7 @@ inline Type Atomic::compareAndSetValue (const Type newValue, const Type va #endif } -template -inline void Atomic::memoryBarrier() noexcept +inline void memoryBarrier() noexcept { #if BEAST_ATOMICS_MAC OSMemoryBarrier(); @@ -389,4 +385,5 @@ inline void Atomic::memoryBarrier() noexcept #pragma warning (pop) #endif -#endif // BEAST_ATOMIC_H_INCLUDED +#endif + diff --git a/modules/beast_core/threads/beast_Thread.cpp b/modules/beast_core/threads/beast_Thread.cpp index fbc5fa5c19..d9d5a7ab3c 100644 --- a/modules/beast_core/threads/beast_Thread.cpp +++ b/modules/beast_core/threads/beast_Thread.cpp @@ -322,14 +322,14 @@ public: test.expect (a.get() == (Type) 10); a += (Type) 15; test.expect (a.get() == (Type) 25); - a.memoryBarrier(); + memoryBarrier(); a -= (Type) 5; test.expect (a.get() == (Type) 20); test.expect (++a == (Type) 21); ++a; test.expect (--a == (Type) 21); test.expect (a.get() == (Type) 21); - a.memoryBarrier(); + memoryBarrier(); testFloat (test); } @@ -338,7 +338,7 @@ public: { Atomic a, b; a = (Type) 21; - a.memoryBarrier(); + memoryBarrier(); /* These are some simple test cases to check the atomics - let me know if any of these assertions fail on your system!