diff options
author | Jonathan Roelofs <jonathan@codesourcery.com> | 2014-09-05 19:45:05 +0000 |
---|---|---|
committer | Jonathan Roelofs <jonathan@codesourcery.com> | 2014-09-05 19:45:05 +0000 |
commit | 8d86b2e6867297fb2109824c67c50de67f3a31f2 (patch) | |
tree | 2176efd32556641409f7d1f4d2fd7a400c1cf405 /src/mutex.cpp | |
parent | d634a2c4047a5d7cfdf255c58b574a9addd4d494 (diff) | |
download | external_libcxx-8d86b2e6867297fb2109824c67c50de67f3a31f2.tar.gz external_libcxx-8d86b2e6867297fb2109824c67c50de67f3a31f2.tar.bz2 external_libcxx-8d86b2e6867297fb2109824c67c50de67f3a31f2.zip |
Allow libc++ to be built on systems without POSIX threads
If you're crazy enough to want this sort of thing, then add
-D_LIBCPP_HAS_NO_THREADS to your CXXFLAGS and
--param=additiona_features=libcpp-has-no-threads to your lit commnad line.
http://reviews.llvm.org/D3969
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@217271 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'src/mutex.cpp')
-rw-r--r-- | src/mutex.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mutex.cpp b/src/mutex.cpp index 07678978a..e56271d30 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -14,6 +14,7 @@ #include "cassert" _LIBCPP_BEGIN_NAMESPACE_STD +#ifndef _LIBCPP_HAS_NO_THREADS const defer_lock_t defer_lock = {}; const try_to_lock_t try_to_lock = {}; @@ -206,18 +207,42 @@ recursive_timed_mutex::unlock() _NOEXCEPT } } +#endif // !_LIBCPP_HAS_NO_THREADS + // If dispatch_once_f ever handles C++ exceptions, and if one can get to it // without illegal macros (unexpected macros not beginning with _UpperCase or // __lowercase), and if it stops spinning waiting threads, then call_once should // call into dispatch_once_f instead of here. Relevant radar this code needs to // keep in sync with: 7741191. +#ifndef _LIBCPP_HAS_NO_THREADS static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cv = PTHREAD_COND_INITIALIZER; +#endif void __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) { +#if defined(_LIBCPP_HAS_NO_THREADS) + if (flag == 0) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + flag = 1; + func(arg); + flag = ~0ul; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + flag = 0ul; + throw; + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +#else // !_LIBCPP_HAS_NO_THREADS pthread_mutex_lock(&mut); while (flag == 1) pthread_cond_wait(&cv, &mut); @@ -248,6 +273,8 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) } else pthread_mutex_unlock(&mut); +#endif // !_LIBCPP_HAS_NO_THREADS + } _LIBCPP_END_NAMESPACE_STD |