Index: include/__refstring =================================================================== --- include/__refstring +++ include/__refstring @@ -83,7 +83,11 @@ : __imp_(s.__imp_) { if (__uses_refcount()) +#ifdef _LIBCPP_HAS_NO_THREADS + ++rep_from_data(__imp_)->count; +#else __sync_add_and_fetch(&rep_from_data(__imp_)->count, 1); +#endif } inline @@ -95,7 +99,11 @@ __sync_add_and_fetch(&rep_from_data(__imp_)->count, 1); if (adjust_old_count) { +#ifdef _LIBCPP_HAS_NO_THREADS + if ((old_rep->count -= count_t(-1)) < 0) +#else if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0) +#endif { ::operator delete(old_rep); } @@ -107,7 +115,11 @@ __libcpp_refstring::~__libcpp_refstring() { if (__uses_refcount()) { _Rep_base* rep = rep_from_data(__imp_); +#ifdef _LIBCPP_HAS_NO_THREADS + if ((rep->count -= count_t(-1)) < 0) { +#else if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) { +#endif ::operator delete(rep); } } Index: src/locale.cpp =================================================================== --- src/locale.cpp +++ src/locale.cpp @@ -667,7 +667,11 @@ void locale::id::__init() { +#ifdef _LIBCPP_HAS_NO_THREADS + __id_ = ++__next_id; +#else __id_ = __sync_add_and_fetch(&__next_id, 1); +#endif } // template <> class collate_byname Index: src/support/runtime/exception_fallback.ipp =================================================================== --- src/support/runtime/exception_fallback.ipp +++ src/support/runtime/exception_fallback.ipp @@ -20,13 +20,23 @@ unexpected_handler set_unexpected(unexpected_handler func) _NOEXCEPT { +#ifdef _LIBCPP_HAS_NO_THREADS + unexpected_handler old = __unexpected_handler; + __unexpected_handler = func; + return old; +#else return __sync_lock_test_and_set(&__unexpected_handler, func); +#endif } unexpected_handler get_unexpected() _NOEXCEPT { +#ifdef _LIBCPP_HAS_NO_THREADS + return __unexpected_handler; +#else return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0); +#endif } @@ -41,14 +51,23 @@ terminate_handler set_terminate(terminate_handler func) _NOEXCEPT { +#ifdef _LIBCPP_HAS_NO_THREADS + terminate_handler old = __terminate_handler; + __terminate_handler = func; + return old; +#else return __sync_lock_test_and_set(&__terminate_handler, func); +#endif } terminate_handler get_terminate() _NOEXCEPT { +#ifdef _LIBCPP_HAS_NO_THREADS + return __terminate_handler; +#else return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0); - +#endif } #ifndef __EMSCRIPTEN__ // We provide this in JS Index: src/support/runtime/new_handler_fallback.ipp =================================================================== --- src/support/runtime/new_handler_fallback.ipp +++ src/support/runtime/new_handler_fallback.ipp @@ -15,13 +15,23 @@ new_handler set_new_handler(new_handler handler) _NOEXCEPT { +#ifdef _LIBCPP_HAS_NO_THREADS + auto old = __new_handler; + __new_handler = handler; + return old; +#else return __sync_lock_test_and_set(&__new_handler, handler); +#endif } new_handler get_new_handler() _NOEXCEPT { +#ifdef _LIBCPP_HAS_NO_THREADS + return __new_handler; +#else return __sync_fetch_and_add(&__new_handler, nullptr); +#endif } } // namespace std