diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-01-15 21:17:36 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-01-15 21:17:36 +0000 |
| commit | d72607e9e28bcdeca1cb370dd3bf119c7853576f (patch) | |
| tree | c7ef11e9501df78a928c64bb92aa05baf56f5808 /contrib/libc++/src/mutex.cpp | |
| parent | f7e6516a1f4099194f051c570a3301dae90729da (diff) | |
| parent | f857581820d15e410e9945d2fcd5f7163be25a96 (diff) | |
Notes
Diffstat (limited to 'contrib/libc++/src/mutex.cpp')
| -rw-r--r-- | contrib/libc++/src/mutex.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/contrib/libc++/src/mutex.cpp b/contrib/libc++/src/mutex.cpp index 07678978a678..e56271d308e6 100644 --- a/contrib/libc++/src/mutex.cpp +++ b/contrib/libc++/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 |
