summaryrefslogtreecommitdiff
path: root/include/memory
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2016-09-04 09:55:12 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2016-09-04 09:55:12 +0000
commit4dbd4fcf8626453949625bf36976e668094cfbb1 (patch)
treebb56168016d3cf4cd4a0f4cee12287b95d2aecb6 /include/memory
parent226cd0674ec0ef4db9c126373e30078f33526d7e (diff)
[libcxx] Fix a data race in call_once
call_once is using relaxed atomic load to perform double-checked locking, which contains a data race. The fast-path load has to be an acquire atomic load. Differential Revision: https://reviews.llvm.org/D24028 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@280621 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/memory')
-rw-r--r--include/memory12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/memory b/include/memory
index 31f58b7c0..8cb094e6b 100644
--- a/include/memory
+++ b/include/memory
@@ -663,6 +663,18 @@ _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
#endif
}
+template <class _ValueType>
+inline _LIBCPP_ALWAYS_INLINE
+_ValueType __libcpp_acquire_load(_ValueType const* __value) {
+#if !defined(_LIBCPP_HAS_NO_THREADS) && \
+ defined(__ATOMIC_ACQUIRE) && \
+ (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
+ return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
+#else
+ return *__value;
+#endif
+}
+
// addressof moved to <__functional_base>
template <class _Tp> class allocator;