[libcxx] Don't assume __libcpp_thread_t is an integral type
We have already refactored the underlying platform thread type into __libcpp_thread_t, but there are few places in the source where we still assume it is an integral type. This patch refactores those points back into the threading API. Differential revision: https://reviews.llvm.org/D28608 Reviewers: EricWF llvm-svn: 292107
This commit is contained in:
parent
238169db60
commit
af762e91b2
|
@ -61,6 +61,8 @@ typedef pthread_once_t __libcpp_exec_once_flag;
|
||||||
typedef pthread_t __libcpp_thread_id;
|
typedef pthread_t __libcpp_thread_id;
|
||||||
|
|
||||||
// Thread
|
// Thread
|
||||||
|
#define _LIBCPP_NULL_THREAD 0U
|
||||||
|
|
||||||
typedef pthread_t __libcpp_thread_t;
|
typedef pthread_t __libcpp_thread_t;
|
||||||
|
|
||||||
// Thrad Local Storage
|
// Thrad Local Storage
|
||||||
|
@ -86,6 +88,8 @@ typedef INIT_ONCE __libcpp_exec_once_flag;
|
||||||
typedef DWORD __libcpp_thread_id;
|
typedef DWORD __libcpp_thread_id;
|
||||||
|
|
||||||
// Thread
|
// Thread
|
||||||
|
#define _LIBCPP_NULL_THREAD 0U
|
||||||
|
|
||||||
typedef HANDLE __libcpp_thread_t;
|
typedef HANDLE __libcpp_thread_t;
|
||||||
|
|
||||||
// Thread Local Storage
|
// Thread Local Storage
|
||||||
|
@ -157,6 +161,9 @@ _LIBCPP_THREAD_ABI_VISIBILITY
|
||||||
bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2);
|
bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2);
|
||||||
|
|
||||||
// Thread
|
// Thread
|
||||||
|
_LIBCPP_THREAD_ABI_VISIBILITY
|
||||||
|
bool __libcpp_thread_isnull(const __libcpp_thread_t *__t);
|
||||||
|
|
||||||
_LIBCPP_THREAD_ABI_VISIBILITY
|
_LIBCPP_THREAD_ABI_VISIBILITY
|
||||||
int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
|
int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
|
||||||
void *__arg);
|
void *__arg);
|
||||||
|
@ -309,6 +316,10 @@ bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thread
|
// Thread
|
||||||
|
bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
|
||||||
|
return *__t == 0;
|
||||||
|
}
|
||||||
|
|
||||||
int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
|
int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
|
||||||
void *__arg)
|
void *__arg)
|
||||||
{
|
{
|
||||||
|
@ -506,6 +517,10 @@ __libcpp_beginthreadex_thunk(void *__raw_data)
|
||||||
return static_cast<unsigned>(reinterpret_cast<uintptr_t>(__func(__arg)));
|
return static_cast<unsigned>(reinterpret_cast<uintptr_t>(__func(__arg)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
|
||||||
|
return *__t == 0;
|
||||||
|
}
|
||||||
|
|
||||||
int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
|
int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
|
||||||
void *__arg)
|
void *__arg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -290,7 +290,7 @@ public:
|
||||||
typedef __libcpp_thread_t native_handle_type;
|
typedef __libcpp_thread_t native_handle_type;
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
thread() _NOEXCEPT : __t_(0) {}
|
thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
|
||||||
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
||||||
template <class _Fp, class ..._Args,
|
template <class _Fp, class ..._Args,
|
||||||
class = typename enable_if
|
class = typename enable_if
|
||||||
|
@ -306,7 +306,7 @@ public:
|
||||||
|
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {__t.__t_ = 0;}
|
thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {__t.__t_ = _LIBCPP_NULL_THREAD;}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
thread& operator=(thread&& __t) _NOEXCEPT;
|
thread& operator=(thread&& __t) _NOEXCEPT;
|
||||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
|
@ -315,7 +315,7 @@ public:
|
||||||
void swap(thread& __t) _NOEXCEPT {_VSTD::swap(__t_, __t.__t_);}
|
void swap(thread& __t) _NOEXCEPT {_VSTD::swap(__t_, __t.__t_);}
|
||||||
|
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
bool joinable() const _NOEXCEPT {return __t_ != 0;}
|
bool joinable() const _NOEXCEPT {return !__libcpp_thread_isnull(&__t_);}
|
||||||
void join();
|
void join();
|
||||||
void detach();
|
void detach();
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
@ -409,10 +409,10 @@ inline
|
||||||
thread&
|
thread&
|
||||||
thread::operator=(thread&& __t) _NOEXCEPT
|
thread::operator=(thread&& __t) _NOEXCEPT
|
||||||
{
|
{
|
||||||
if (__t_ != 0)
|
if (!__libcpp_thread_isnull(&__t_))
|
||||||
terminate();
|
terminate();
|
||||||
__t_ = __t.__t_;
|
__t_ = __t.__t_;
|
||||||
__t.__t_ = 0;
|
__t.__t_ = _LIBCPP_NULL_THREAD;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue