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 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@268734 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -179,9 +179,7 @@ template<class Callable, class ...Args>
|
||||
#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 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
class _LIBCPP_TYPE_VIS recursive_mutex
|
||||
{
|
||||
pthread_mutex_t __m_;
|
||||
__libcpp_mutex_t __m_;
|
||||
|
||||
public:
|
||||
recursive_mutex();
|
||||
@@ -210,7 +208,7 @@ public:
|
||||
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 @@ class _LIBCPP_TYPE_VIS recursive_timed_mutex
|
||||
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 @@ bool
|
||||
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 @@ lock(_L0& __l0, _L1& __l1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
sched_yield();
|
||||
__libcpp_thread_yield();
|
||||
{
|
||||
unique_lock<_L1> __u1(__l1);
|
||||
if (__l0.try_lock())
|
||||
@@ -371,7 +369,7 @@ lock(_L0& __l0, _L1& __l1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
sched_yield();
|
||||
__libcpp_thread_yield();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +394,7 @@ __lock_first(int __i, _L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
|
||||
}
|
||||
}
|
||||
++__i;
|
||||
sched_yield();
|
||||
__libcpp_thread_yield();
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
@@ -412,7 +410,7 @@ __lock_first(int __i, _L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
|
||||
__i = 0;
|
||||
else
|
||||
__i += 2;
|
||||
sched_yield();
|
||||
__libcpp_thread_yield();
|
||||
break;
|
||||
default:
|
||||
__lock_first(__i - 2, __l2, __l3..., __l0, __l1);
|
||||
|
||||
Reference in New Issue
Block a user