diff options
Diffstat (limited to 'libcxx/src/memory.cpp')
-rw-r--r-- | libcxx/src/memory.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libcxx/src/memory.cpp b/libcxx/src/memory.cpp index 7caab26c42e..1c108b8c352 100644 --- a/libcxx/src/memory.cpp +++ b/libcxx/src/memory.cpp @@ -10,6 +10,7 @@ #define _LIBCPP_BUILDING_MEMORY #include "memory" #include "mutex" +#include "thread" _LIBCPP_BEGIN_NAMESPACE_STD @@ -129,13 +130,23 @@ _LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT void __sp_mut::lock() _NOEXCEPT { - reinterpret_cast<mutex*>(_)->lock(); + mutex& m = *static_cast<mutex*>(_); + unsigned count = 0; + while (!m.try_lock()) + { + if (++count > 16) + { + m.lock(); + break; + } + this_thread::yield(); + } } void __sp_mut::unlock() _NOEXCEPT { - reinterpret_cast<mutex*>(_)->unlock(); + static_cast<mutex*>(_)->unlock(); } __sp_mut& |