diff options
author | Eric Fiselier <eric@efcs.ca> | 2015-07-07 00:27:16 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2015-07-07 00:27:16 +0000 |
commit | 1faf289e27bcb54e54b2e3e0f492d6f54d59cd9e (patch) | |
tree | e3663203fe77563429ca010009a19d2d2c926dcd /libcxx/src/mutex.cpp | |
parent | d529d04fd73c55f35d3f6425314a6780e9146f23 (diff) | |
download | bcm5719-llvm-1faf289e27bcb54e54b2e3e0f492d6f54d59cd9e.tar.gz bcm5719-llvm-1faf289e27bcb54e54b2e3e0f492d6f54d59cd9e.zip |
[libcxx] Add atomic_support.h header to src that handles needed atomic operations.
Summary:
In some places in libc++ we need to use the `__atomic_*` builtins. This patch adds a header that provides access to those builtins in a uniform way from within the dylib source.
If the compiler building the dylib does not support these builtins then a warning is issued.
Only relaxed loads are needed within the headers. A singe function to do these relaxed loads has been added to `<memory>`.
This patch applies the new atomic builtins to `__shared_count` and `call_once`.
Reviewers: mclow.lists
Subscribers: majnemer, jroelofs, cfe-commits
Differential Revision: http://reviews.llvm.org/D10406
llvm-svn: 241532
Diffstat (limited to 'libcxx/src/mutex.cpp')
-rw-r--r-- | libcxx/src/mutex.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/libcxx/src/mutex.cpp b/libcxx/src/mutex.cpp index e56271d308e..5f8ba0a0826 100644 --- a/libcxx/src/mutex.cpp +++ b/libcxx/src/mutex.cpp @@ -12,6 +12,7 @@ #include "limits" #include "system_error" #include "cassert" +#include "support/atomic_support.h" _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_HAS_NO_THREADS @@ -220,6 +221,9 @@ static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cv = PTHREAD_COND_INITIALIZER; #endif +/// NOTE: Changes to flag are done via relaxed atomic stores +/// even though the accesses are protected by a mutex because threads +/// just entering 'call_once` concurrently read from flag. void __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) { @@ -252,11 +256,11 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) try { #endif // _LIBCPP_NO_EXCEPTIONS - flag = 1; + __libcpp_relaxed_store(&flag, 1ul); pthread_mutex_unlock(&mut); func(arg); pthread_mutex_lock(&mut); - flag = ~0ul; + __libcpp_relaxed_store(&flag, ~0ul); pthread_mutex_unlock(&mut); pthread_cond_broadcast(&cv); #ifndef _LIBCPP_NO_EXCEPTIONS @@ -264,7 +268,7 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) catch (...) { pthread_mutex_lock(&mut); - flag = 0ul; + __libcpp_relaxed_store(&flag, 0ul); pthread_mutex_unlock(&mut); pthread_cond_broadcast(&cv); throw; |