Refactor pthread usage of libcxx.
This patch extracts out all the pthread dependencies of libcxx into the
new header __threading_support. The motivation is to make it easy to
re-target libcxx into platforms that do not support pthread.
Original patch from Fulvio Esposito (fulvio.esposito@outlook.com) - D11781
Applied with tweaks - D19412
Change-Id: I301111f0075de93dd8129416e06babc195aa936b
llvm-svn: 268734
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: c7e4239fabf2c876449697caf05a342b01bf0312
diff --git a/include/mutex b/include/mutex
index a0875a5..4d288ae 100644
--- a/include/mutex
+++ b/include/mutex
@@ -179,9 +179,7 @@
#ifndef _LIBCPP_HAS_NO_VARIADICS
#include <tuple>
#endif
-#ifndef _LIBCPP_HAS_NO_THREADS
-#include <sched.h>
-#endif
+#include <__threading_support>
#include <__undef_min_max>
@@ -195,7 +193,7 @@
class _LIBCPP_TYPE_VIS recursive_mutex
{
- pthread_mutex_t __m_;
+ __libcpp_mutex_t __m_;
public:
recursive_mutex();
@@ -210,7 +208,7 @@
bool try_lock() _NOEXCEPT;
void unlock() _NOEXCEPT;
- typedef pthread_mutex_t* native_handle_type;
+ typedef __libcpp_mutex_t* native_handle_type;
_LIBCPP_INLINE_VISIBILITY
native_handle_type native_handle() {return &__m_;}
};
@@ -262,7 +260,7 @@
mutex __m_;
condition_variable __cv_;
size_t __count_;
- pthread_t __id_;
+ __libcpp_thread_id __id_;
public:
recursive_timed_mutex();
~recursive_timed_mutex();
@@ -288,9 +286,9 @@
recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
{
using namespace chrono;
- pthread_t __id = pthread_self();
+ __libcpp_thread_id __id = __libcpp_thread_get_current_id();
unique_lock<mutex> lk(__m_);
- if (pthread_equal(__id, __id_))
+ if (__libcpp_thread_id_equal(__id, __id_))
{
if (__count_ == numeric_limits<size_t>::max())
return false;
@@ -362,7 +360,7 @@
break;
}
}
- sched_yield();
+ __libcpp_thread_yield();
{
unique_lock<_L1> __u1(__l1);
if (__l0.try_lock())
@@ -371,7 +369,7 @@
break;
}
}
- sched_yield();
+ __libcpp_thread_yield();
}
}
@@ -396,7 +394,7 @@
}
}
++__i;
- sched_yield();
+ __libcpp_thread_yield();
break;
case 1:
{
@@ -412,7 +410,7 @@
__i = 0;
else
__i += 2;
- sched_yield();
+ __libcpp_thread_yield();
break;
default:
__lock_first(__i - 2, __l2, __l3..., __l0, __l1);