diff --git a/libcxx/src/debug.cpp b/libcxx/src/debug.cpp --- a/libcxx/src/debug.cpp +++ b/libcxx/src/debug.cpp @@ -62,7 +62,31 @@ { #ifndef _LIBCPP_HAS_NO_THREADS -typedef mutex mutex_type; +/// Simple wrapper around std::mutex that checks threads are enabled before doing anything. +class mutex_check_threading : public mutex { + /// Threads enabled/disabled status should not change over the life of the process. + static const bool threadsEnabled; + + public: + void lock() { + if (!threadsEnabled) + return; + mutex::lock(); + } + bool try_lock() { + if (!threadsEnabled) + return true; + return mutex::try_lock(); + } + void unlock() { + if (!threadsEnabled) + return; + mutex::unlock(); + } +}; +const bool mutex_check_threading::threadsEnabled = __libcpp_are_threads_enabled(); + +typedef mutex_check_threading mutex_type; typedef lock_guard WLock; typedef lock_guard RLock;