thread_support: split out {,non-}recursive mutex
Split out the recursive and non-recursive mutex. This split is needed for platforms which may use differing types for the two mutex (e.g. Win32 threads). git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291145 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -63,6 +63,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||||||
typedef pthread_mutex_t __libcpp_mutex_t;
|
typedef pthread_mutex_t __libcpp_mutex_t;
|
||||||
#define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
#define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||||
|
|
||||||
|
typedef pthread_mutex_t __libcpp_recursive_mutex_t;
|
||||||
|
|
||||||
// Condition Variable
|
// Condition Variable
|
||||||
typedef pthread_cond_t __libcpp_condvar_t;
|
typedef pthread_cond_t __libcpp_condvar_t;
|
||||||
#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
|
#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
|
||||||
@@ -83,7 +85,19 @@ typedef pthread_key_t __libcpp_tls_key;
|
|||||||
|
|
||||||
// Mutex
|
// Mutex
|
||||||
_LIBCPP_THREAD_ABI_VISIBILITY
|
_LIBCPP_THREAD_ABI_VISIBILITY
|
||||||
int __libcpp_recursive_mutex_init(__libcpp_mutex_t *__m);
|
int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m);
|
||||||
|
|
||||||
|
_LIBCPP_THREAD_ABI_VISIBILITY
|
||||||
|
int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m);
|
||||||
|
|
||||||
|
_LIBCPP_THREAD_ABI_VISIBILITY
|
||||||
|
int __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m);
|
||||||
|
|
||||||
|
_LIBCPP_THREAD_ABI_VISIBILITY
|
||||||
|
int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m);
|
||||||
|
|
||||||
|
_LIBCPP_THREAD_ABI_VISIBILITY
|
||||||
|
int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m);
|
||||||
|
|
||||||
_LIBCPP_THREAD_ABI_VISIBILITY
|
_LIBCPP_THREAD_ABI_VISIBILITY
|
||||||
int __libcpp_mutex_lock(__libcpp_mutex_t *__m);
|
int __libcpp_mutex_lock(__libcpp_mutex_t *__m);
|
||||||
@@ -164,7 +178,7 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
|
|||||||
#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
|
#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
|
||||||
defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
|
defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
|
||||||
|
|
||||||
int __libcpp_recursive_mutex_init(__libcpp_mutex_t *__m)
|
int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
|
||||||
{
|
{
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
int __ec = pthread_mutexattr_init(&attr);
|
int __ec = pthread_mutexattr_init(&attr);
|
||||||
@@ -188,6 +202,26 @@ int __libcpp_recursive_mutex_init(__libcpp_mutex_t *__m)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m)
|
||||||
|
{
|
||||||
|
return pthread_mutex_lock(__m);
|
||||||
|
}
|
||||||
|
|
||||||
|
int __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
|
||||||
|
{
|
||||||
|
return pthread_mutex_trylock(__m);
|
||||||
|
}
|
||||||
|
|
||||||
|
int __libcpp_recursive_mutex_unlock(__libcpp_mutex_t *__m)
|
||||||
|
{
|
||||||
|
return pthread_mutex_unlock(__m);
|
||||||
|
}
|
||||||
|
|
||||||
|
int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m)
|
||||||
|
{
|
||||||
|
return pthread_mutex_destroy(__m);
|
||||||
|
}
|
||||||
|
|
||||||
int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
|
int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
|
||||||
{
|
{
|
||||||
return pthread_mutex_lock(__m);
|
return pthread_mutex_lock(__m);
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||||||
|
|
||||||
class _LIBCPP_TYPE_VIS recursive_mutex
|
class _LIBCPP_TYPE_VIS recursive_mutex
|
||||||
{
|
{
|
||||||
__libcpp_mutex_t __m_;
|
__libcpp_recursive_mutex_t __m_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
recursive_mutex();
|
recursive_mutex();
|
||||||
@@ -221,7 +221,8 @@ public:
|
|||||||
bool try_lock() _NOEXCEPT;
|
bool try_lock() _NOEXCEPT;
|
||||||
void unlock() _NOEXCEPT;
|
void unlock() _NOEXCEPT;
|
||||||
|
|
||||||
typedef __libcpp_mutex_t* native_handle_type;
|
typedef __libcpp_recursive_mutex_t* native_handle_type;
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
native_handle_type native_handle() {return &__m_;}
|
native_handle_type native_handle() {return &__m_;}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ recursive_mutex::recursive_mutex()
|
|||||||
|
|
||||||
recursive_mutex::~recursive_mutex()
|
recursive_mutex::~recursive_mutex()
|
||||||
{
|
{
|
||||||
int e = __libcpp_mutex_destroy(&__m_);
|
int e = __libcpp_recursive_mutex_destroy(&__m_);
|
||||||
(void)e;
|
(void)e;
|
||||||
assert(e == 0);
|
assert(e == 0);
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ recursive_mutex::~recursive_mutex()
|
|||||||
void
|
void
|
||||||
recursive_mutex::lock()
|
recursive_mutex::lock()
|
||||||
{
|
{
|
||||||
int ec = __libcpp_mutex_lock(&__m_);
|
int ec = __libcpp_recursive_mutex_lock(&__m_);
|
||||||
if (ec)
|
if (ec)
|
||||||
__throw_system_error(ec, "recursive_mutex lock failed");
|
__throw_system_error(ec, "recursive_mutex lock failed");
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ recursive_mutex::lock()
|
|||||||
void
|
void
|
||||||
recursive_mutex::unlock() _NOEXCEPT
|
recursive_mutex::unlock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
int e = __libcpp_mutex_unlock(&__m_);
|
int e = __libcpp_recursive_mutex_unlock(&__m_);
|
||||||
(void)e;
|
(void)e;
|
||||||
assert(e == 0);
|
assert(e == 0);
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ recursive_mutex::unlock() _NOEXCEPT
|
|||||||
bool
|
bool
|
||||||
recursive_mutex::try_lock() _NOEXCEPT
|
recursive_mutex::try_lock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
return __libcpp_mutex_trylock(&__m_) == 0;
|
return __libcpp_recursive_mutex_trylock(&__m_) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// timed_mutex
|
// timed_mutex
|
||||||
|
|||||||
Reference in New Issue
Block a user