diff options
| author | Kuba Brecka <kuba.brecka@gmail.com> | 2016-09-04 09:55:12 +0000 |
|---|---|---|
| committer | Kuba Brecka <kuba.brecka@gmail.com> | 2016-09-04 09:55:12 +0000 |
| commit | 224264ade0674f8ce120432614abfd880323f105 (patch) | |
| tree | 3f61523a69c3dab582196d1c5a887ee392262a95 /libcxx/include/memory | |
| parent | ccd44939ef93dae2822fbfc6ff6eb3d2376ad2f2 (diff) | |
| download | bcm5719-llvm-224264ade0674f8ce120432614abfd880323f105.tar.gz bcm5719-llvm-224264ade0674f8ce120432614abfd880323f105.zip | |
[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
llvm-svn: 280621
Diffstat (limited to 'libcxx/include/memory')
| -rw-r--r-- | libcxx/include/memory | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libcxx/include/memory b/libcxx/include/memory index 31f58b7c0a4..8cb094e6b6a 100644 --- a/libcxx/include/memory +++ b/libcxx/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; |

