Index: Source/wtf/Threading.h |
diff --git a/Source/wtf/Threading.h b/Source/wtf/Threading.h |
index 97d4cb390ae0734e9b214a95207e47713bebe7d3..61207e33ed5eeceea06da42ba9f4ad92b4c541d3 100644 |
--- a/Source/wtf/Threading.h |
+++ b/Source/wtf/Threading.h |
@@ -30,14 +30,23 @@ |
#ifndef Threading_h |
#define Threading_h |
+#include "wtf/Atomics.h" |
+#include "wtf/TypeTraits.h" |
#include "wtf/WTFExport.h" |
#include <stdint.h> |
-// For portability, we do not use thread-safe statics natively supported by some compilers (e.g. gcc). |
-#define AtomicallyInitializedStatic(T, name) \ |
- WTF::lockAtomicallyInitializedStaticMutex(); \ |
- static T name; \ |
- WTF::unlockAtomicallyInitializedStaticMutex(); |
+// For portability, we do not make use of C++11 thread-safe statics, as supported |
+// by some toolchains. |
+#define AtomicallyInitializedStaticReference(T, name, initializer) \ |
+ /* Double-checked locking; init to nullptr is thread-safe on all implementations. */ \ |
+ static WTF::RemoveConst<T>::Type* name##_pointer = nullptr; \ |
haraken
2015/01/21 15:23:33
_pointer => Pointer
sof
2015/01/21 15:51:38
Thanks, switched.
|
+ if (!WTF::acquireLoad(reinterpret_cast<void* const*>(&name##_pointer))) { \ |
+ WTF::lockAtomicallyInitializedStaticMutex(); \ |
+ if (!WTF::acquireLoad(reinterpret_cast<void* const*>(&name##_pointer))) \ |
+ WTF::releaseStore(reinterpret_cast<void**>(&name##_pointer), initializer); \ |
+ WTF::unlockAtomicallyInitializedStaticMutex(); \ |
+ } \ |
+ T& name = *name##_pointer |
namespace WTF { |