diff options
Diffstat (limited to 'libcxx/src')
| -rw-r--r-- | libcxx/src/algorithm.cpp | 8 | ||||
| -rw-r--r-- | libcxx/src/condition_variable.cpp | 6 | ||||
| -rw-r--r-- | libcxx/src/debug.cpp | 40 | ||||
| -rw-r--r-- | libcxx/src/future.cpp | 6 | ||||
| -rw-r--r-- | libcxx/src/ios.cpp | 2 | ||||
| -rw-r--r-- | libcxx/src/memory.cpp | 6 | ||||
| -rw-r--r-- | libcxx/src/mutex.cpp | 27 | ||||
| -rw-r--r-- | libcxx/src/shared_mutex.cpp | 5 | ||||
| -rw-r--r-- | libcxx/src/thread.cpp | 5 |
9 files changed, 102 insertions, 3 deletions
diff --git a/libcxx/src/algorithm.cpp b/libcxx/src/algorithm.cpp index 6d5cf7c0bc8..e548856ff6e 100644 --- a/libcxx/src/algorithm.cpp +++ b/libcxx/src/algorithm.cpp @@ -47,12 +47,16 @@ template bool __insertion_sort_incomplete<__less<long double>&, long double*>(lo template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&); +#ifndef _LIBCPP_HAS_NO_THREADS static pthread_mutex_t __rs_mut = PTHREAD_MUTEX_INITIALIZER; +#endif unsigned __rs_default::__c_ = 0; __rs_default::__rs_default() { +#ifndef _LIBCPP_HAS_NO_THREADS pthread_mutex_lock(&__rs_mut); +#endif __c_ = 1; } @@ -63,8 +67,12 @@ __rs_default::__rs_default(const __rs_default&) __rs_default::~__rs_default() { +#ifndef _LIBCPP_HAS_NO_THREADS if (--__c_ == 0) pthread_mutex_unlock(&__rs_mut); +#else + --__c_; +#endif } __rs_default::result_type diff --git a/libcxx/src/condition_variable.cpp b/libcxx/src/condition_variable.cpp index 061d1388d3e..5fd5fc891c1 100644 --- a/libcxx/src/condition_variable.cpp +++ b/libcxx/src/condition_variable.cpp @@ -7,6 +7,10 @@ // //===----------------------------------------------------------------------===// +#include "__config" + +#ifndef _LIBCPP_HAS_NO_THREADS + #include "condition_variable" #include "thread" #include "system_error" @@ -79,3 +83,5 @@ notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk) } _LIBCPP_END_NAMESPACE_STD + +#endif // !_LIBCPP_HAS_NO_THREADS diff --git a/libcxx/src/debug.cpp b/libcxx/src/debug.cpp index d0e867957dc..60694a3bdb0 100644 --- a/libcxx/src/debug.cpp +++ b/libcxx/src/debug.cpp @@ -35,6 +35,7 @@ __get_const_db() namespace { +#ifndef _LIBCPP_HAS_NO_THREADS typedef mutex mutex_type; typedef lock_guard<mutex_type> WLock; typedef lock_guard<mutex_type> RLock; @@ -45,6 +46,7 @@ mut() static mutex_type m; return m; } +#endif // !_LIBCPP_HAS_NO_THREADS } // unnamed namespace @@ -108,7 +110,9 @@ __libcpp_db::~__libcpp_db() void* __libcpp_db::__find_c_from_i(void* __i) const { +#ifndef _LIBCPP_HAS_NO_THREADS RLock _(mut()); +#endif __i_node* i = __find_iterator(__i); _LIBCPP_ASSERT(i != nullptr, "iterator not found in debug database."); return i->__c_ != nullptr ? i->__c_->__c_ : nullptr; @@ -117,7 +121,9 @@ __libcpp_db::__find_c_from_i(void* __i) const void __libcpp_db::__insert_ic(void* __i, const void* __c) { +#ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); +#endif if (__cbeg_ == __cend_) return; size_t hc = hash<const void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_); @@ -138,7 +144,9 @@ __libcpp_db::__insert_ic(void* __i, const void* __c) __c_node* __libcpp_db::__insert_c(void* __c) { +#ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); +#endif if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_)) { size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1); @@ -184,7 +192,9 @@ __libcpp_db::__insert_c(void* __c) void __libcpp_db::__erase_i(void* __i) { +#ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); +#endif if (__ibeg_ != __iend_) { size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_); @@ -215,7 +225,9 @@ __libcpp_db::__erase_i(void* __i) void __libcpp_db::__invalidate_all(void* __c) { +#ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); +#endif if (__cend_ != __cbeg_) { size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_); @@ -239,17 +251,23 @@ __libcpp_db::__invalidate_all(void* __c) __c_node* __libcpp_db::__find_c_and_lock(void* __c) const { +#ifndef _LIBCPP_HAS_NO_THREADS mut().lock(); +#endif if (__cend_ == __cbeg_) { +#ifndef _LIBCPP_HAS_NO_THREADS mut().unlock(); +#endif return nullptr; } size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_); __c_node* p = __cbeg_[hc]; if (p == nullptr) { +#ifndef _LIBCPP_HAS_NO_THREADS mut().unlock(); +#endif return nullptr; } while (p->__c_ != __c) @@ -257,7 +275,9 @@ __libcpp_db::__find_c_and_lock(void* __c) const p = p->__next_; if (p == nullptr) { +#ifndef _LIBCPP_HAS_NO_THREADS mut().unlock(); +#endif return nullptr; } } @@ -281,13 +301,17 @@ __libcpp_db::__find_c(void* __c) const void __libcpp_db::unlock() const { +#ifndef _LIBCPP_HAS_NO_THREADS mut().unlock(); +#endif } void __libcpp_db::__erase_c(void* __c) { +#ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); +#endif if (__cend_ != __cbeg_) { size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_); @@ -322,7 +346,9 @@ __libcpp_db::__erase_c(void* __c) void __libcpp_db::__iterator_copy(void* __i, const void* __i0) { +#ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); +#endif __i_node* i = __find_iterator(__i); __i_node* i0 = __find_iterator(__i0); __c_node* c0 = i0 != nullptr ? i0->__c_ : nullptr; @@ -348,7 +374,9 @@ __libcpp_db::__iterator_copy(void* __i, const void* __i0) bool __libcpp_db::__dereferenceable(const void* __i) const { +#ifndef _LIBCPP_HAS_NO_THREADS RLock _(mut()); +#endif __i_node* i = __find_iterator(__i); return i != nullptr && i->__c_ != nullptr && i->__c_->__dereferenceable(__i); } @@ -356,7 +384,9 @@ __libcpp_db::__dereferenceable(const void* __i) const bool __libcpp_db::__decrementable(const void* __i) const { +#ifndef _LIBCPP_HAS_NO_THREADS RLock _(mut()); +#endif __i_node* i = __find_iterator(__i); return i != nullptr && i->__c_ != nullptr && i->__c_->__decrementable(__i); } @@ -364,7 +394,9 @@ __libcpp_db::__decrementable(const void* __i) const bool __libcpp_db::__addable(const void* __i, ptrdiff_t __n) const { +#ifndef _LIBCPP_HAS_NO_THREADS RLock _(mut()); +#endif __i_node* i = __find_iterator(__i); return i != nullptr && i->__c_ != nullptr && i->__c_->__addable(__i, __n); } @@ -372,7 +404,9 @@ __libcpp_db::__addable(const void* __i, ptrdiff_t __n) const bool __libcpp_db::__subscriptable(const void* __i, ptrdiff_t __n) const { +#ifndef _LIBCPP_HAS_NO_THREADS RLock _(mut()); +#endif __i_node* i = __find_iterator(__i); return i != nullptr && i->__c_ != nullptr && i->__c_->__subscriptable(__i, __n); } @@ -380,7 +414,9 @@ __libcpp_db::__subscriptable(const void* __i, ptrdiff_t __n) const bool __libcpp_db::__less_than_comparable(const void* __i, const void* __j) const { +#ifndef _LIBCPP_HAS_NO_THREADS RLock _(mut()); +#endif __i_node* i = __find_iterator(__i); __i_node* j = __find_iterator(__j); __c_node* ci = i != nullptr ? i->__c_ : nullptr; @@ -391,7 +427,9 @@ __libcpp_db::__less_than_comparable(const void* __i, const void* __j) const void __libcpp_db::swap(void* c1, void* c2) { +#ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); +#endif size_t hc = hash<void*>()(c1) % static_cast<size_t>(__cend_ - __cbeg_); __c_node* p1 = __cbeg_[hc]; _LIBCPP_ASSERT(p1 != nullptr, "debug mode internal logic error swap A"); @@ -420,7 +458,9 @@ __libcpp_db::swap(void* c1, void* c2) void __libcpp_db::__insert_i(void* __i) { +#ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); +#endif __insert_iterator(__i); } diff --git a/libcxx/src/future.cpp b/libcxx/src/future.cpp index c67dc58826e..0c5c2c4488d 100644 --- a/libcxx/src/future.cpp +++ b/libcxx/src/future.cpp @@ -7,6 +7,10 @@ // //===----------------------------------------------------------------------===// +#include "__config" + +#ifndef _LIBCPP_HAS_NO_THREADS + #include "future" #include "string" @@ -298,3 +302,5 @@ shared_future<void>::operator=(const shared_future& __rhs) } _LIBCPP_END_NAMESPACE_STD + +#endif // !_LIBCPP_HAS_NO_THREADS diff --git a/libcxx/src/ios.cpp b/libcxx/src/ios.cpp index b71d7da1a8b..0bd500bf3c2 100644 --- a/libcxx/src/ios.cpp +++ b/libcxx/src/ios.cpp @@ -148,7 +148,7 @@ ios_base::getloc() const } // xalloc -#if __has_feature(cxx_atomic) +#if __has_feature(cxx_atomic) && !_LIBCPP_HAS_NO_THREADS atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0); #else int ios_base::__xindex_ = 0; diff --git a/libcxx/src/memory.cpp b/libcxx/src/memory.cpp index 666673fc6b4..31e823cf419 100644 --- a/libcxx/src/memory.cpp +++ b/libcxx/src/memory.cpp @@ -9,8 +9,10 @@ #define _LIBCPP_BUILDING_MEMORY #include "memory" +#ifndef _LIBCPP_HAS_NO_THREADS #include "mutex" #include "thread" +#endif _LIBCPP_BEGIN_NAMESPACE_STD @@ -119,7 +121,7 @@ __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT #endif // _LIBCPP_NO_RTTI -#if __has_feature(cxx_atomic) +#if __has_feature(cxx_atomic) && !_LIBCPP_HAS_NO_THREADS static const std::size_t __sp_mut_count = 16; static pthread_mutex_t mut_back_imp[__sp_mut_count] = @@ -172,7 +174,7 @@ __get_sp_mut(const void* p) return muts[hash<const void*>()(p) & (__sp_mut_count-1)]; } -#endif // __has_feature(cxx_atomic) +#endif // __has_feature(cxx_atomic) && !_LIBCPP_HAS_NO_THREADS void declare_reachable(void*) diff --git a/libcxx/src/mutex.cpp b/libcxx/src/mutex.cpp index 07678978a67..e56271d308e 100644 --- a/libcxx/src/mutex.cpp +++ b/libcxx/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 diff --git a/libcxx/src/shared_mutex.cpp b/libcxx/src/shared_mutex.cpp index dd78a1647fe..2b78c1feb9f 100644 --- a/libcxx/src/shared_mutex.cpp +++ b/libcxx/src/shared_mutex.cpp @@ -7,6 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "__config" +#ifndef _LIBCPP_HAS_NO_THREADS + #define _LIBCPP_BUILDING_SHARED_MUTEX #include "shared_mutex" @@ -99,3 +102,5 @@ shared_timed_mutex::unlock_shared() _LIBCPP_END_NAMESPACE_STD + +#endif // !_LIBCPP_HAS_NO_THREADS diff --git a/libcxx/src/thread.cpp b/libcxx/src/thread.cpp index e6f57c46a7d..0ced1e3bba1 100644 --- a/libcxx/src/thread.cpp +++ b/libcxx/src/thread.cpp @@ -7,6 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "__config" +#ifndef _LIBCPP_HAS_NO_THREADS + #include "thread" #include "exception" #include "vector" @@ -225,3 +228,5 @@ __thread_struct::__make_ready_at_thread_exit(__assoc_sub_state* __s) } _LIBCPP_END_NAMESPACE_STD + +#endif // !_LIBCPP_HAS_NO_THREADS |

