From af762e91b2fe8b7aea7c5b0b7f2d831f8332860b Mon Sep 17 00:00:00 2001 From: Asiri Rathnayake Date: Mon, 16 Jan 2017 12:19:54 +0000 Subject: [PATCH] [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 --- libcxx/include/__threading_support | 15 +++++++++++++++ libcxx/include/thread | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support index 8ecc0ed12bff..13ab769ba93d 100644 --- a/libcxx/include/__threading_support +++ b/libcxx/include/__threading_support @@ -61,6 +61,8 @@ typedef pthread_once_t __libcpp_exec_once_flag; typedef pthread_t __libcpp_thread_id; // Thread +#define _LIBCPP_NULL_THREAD 0U + typedef pthread_t __libcpp_thread_t; // Thrad Local Storage @@ -86,6 +88,8 @@ typedef INIT_ONCE __libcpp_exec_once_flag; typedef DWORD __libcpp_thread_id; // Thread +#define _LIBCPP_NULL_THREAD 0U + typedef HANDLE __libcpp_thread_t; // Thread Local Storage @@ -157,6 +161,9 @@ _LIBCPP_THREAD_ABI_VISIBILITY bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2); // Thread +_LIBCPP_THREAD_ABI_VISIBILITY +bool __libcpp_thread_isnull(const __libcpp_thread_t *__t); + _LIBCPP_THREAD_ABI_VISIBILITY int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), void *__arg); @@ -309,6 +316,10 @@ bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2) } // Thread +bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) { + return *__t == 0; +} + int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), void *__arg) { @@ -506,6 +517,10 @@ __libcpp_beginthreadex_thunk(void *__raw_data) return static_cast(reinterpret_cast(__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 *), void *__arg) { diff --git a/libcxx/include/thread b/libcxx/include/thread index 479e3c08f809..602445644fc4 100644 --- a/libcxx/include/thread +++ b/libcxx/include/thread @@ -290,7 +290,7 @@ public: typedef __libcpp_thread_t native_handle_type; _LIBCPP_INLINE_VISIBILITY - thread() _NOEXCEPT : __t_(0) {} + thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {} #ifndef _LIBCPP_HAS_NO_VARIADICS template