Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1778)

Unified Diff: Source/wtf/Atomics.h

Issue 794223003: Cheaper thread-safe atomic initialization of static references. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add type check for initial value Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/wtf/Atomics.h
diff --git a/Source/wtf/Atomics.h b/Source/wtf/Atomics.h
index 55b99a82f8f529ad7eea07a02ad18452906640f0..3c8da97835489527a4a603fae99584d2aaf2eb13 100644
--- a/Source/wtf/Atomics.h
+++ b/Source/wtf/Atomics.h
@@ -143,6 +143,14 @@ ALWAYS_INLINE void releaseStore(volatile unsigned* ptr, unsigned value)
{
__tsan_atomic32_store(reinterpret_cast<volatile int*>(ptr), static_cast<int>(value), __tsan_memory_order_release);
}
+ALWAYS_INLINE void releaseStore(void* volatile* ptr, void* value)
+{
+#if CPU(64BIT)
+ __tsan_atomic64_store(reinterpret_cast<volatile long*>(ptr), reinterpret_cast<long>(value), __tsan_memory_order_release);
+#else
+ __tsan_atomic32_store(reinterpret_cast<volatile long*>(ptr), reinterpret_cast<long>(value), __tsan_memory_order_release);
+#endif
+}
ALWAYS_INLINE int acquireLoad(volatile const int* ptr)
{
@@ -160,6 +168,14 @@ ALWAYS_INLINE unsigned long acquireLoad(volatile const unsigned long* ptr)
return static_cast<unsigned long>(__tsan_atomic32_load(reinterpret_cast<volatile const long*>(ptr), __tsan_memory_order_acquire));
#endif
}
+ALWAYS_INLINE void* acquireLoad(void* volatile const* ptr)
+{
+#if CPU(64BIT)
+ return reinterpret_cast<void*>(__tsan_atomic64_load(reinterpret_cast<volatile const long*>(ptr), __tsan_memory_order_acquire));
+#else
+ return reinterpret_cast<void*>(__tsan_atomic32_load(reinterpret_cast<volatile const long*>(ptr), __tsan_memory_order_acquire));
+#endif
+}
#else
@@ -199,6 +215,11 @@ ALWAYS_INLINE void releaseStore(volatile unsigned* ptr, unsigned value)
MEMORY_BARRIER();
*ptr = value;
}
+ALWAYS_INLINE void releaseStore(void* volatile* ptr, void* value)
+{
+ MEMORY_BARRIER();
+ *ptr = value;
+}
ALWAYS_INLINE int acquireLoad(volatile const int* ptr)
{
@@ -224,6 +245,12 @@ ALWAYS_INLINE unsigned long long acquireLoad(volatile const unsigned long long*
MEMORY_BARRIER();
return value;
}
+ALWAYS_INLINE void* acquireLoad(void* volatile const* ptr)
+{
+ void* value = *ptr;
+ MEMORY_BARRIER();
+ return value;
+}
#if defined(ADDRESS_SANITIZER)

Powered by Google App Engine
This is Rietveld 408576698