[PATCH] D28608: [libcxx] Don't assume __libcpp_thread_t is an integral type.
Asiri Rathnayake via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 12 05:43:37 PST 2017
rmaprath created this revision.
rmaprath added reviewers: compnerd, EricWF.
rmaprath added a subscriber: cfe-commits.
We have refactored the underlying platform thread type into `__libcpp_thread_t`, but there are few places in the source where it is assumed to be an integral type.
This was discovered while trying to port `libcxx` onto a platform with a slightly wonkier threading system.
https://reviews.llvm.org/D28608
Files:
include/__threading_support
include/thread
Index: include/thread
===================================================================
--- include/thread
+++ include/thread
@@ -290,7 +290,7 @@
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 <class _Fp, class ..._Args,
class = typename enable_if
@@ -306,16 +306,16 @@
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_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
thread& operator=(thread&& __t) _NOEXCEPT;
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
void swap(thread& __t) _NOEXCEPT {_VSTD::swap(__t_, __t.__t_);}
_LIBCPP_INLINE_VISIBILITY
- bool joinable() const _NOEXCEPT {return __t_ != 0;}
+ bool joinable() const _NOEXCEPT {return !__libcpp_thread_isnull(&__t_);}
void join();
void detach();
_LIBCPP_INLINE_VISIBILITY
@@ -409,10 +409,10 @@
thread&
thread::operator=(thread&& __t) _NOEXCEPT
{
- if (__t_ != 0)
+ if (!__libcpp_thread_isnull(&__t_))
terminate();
__t_ = __t.__t_;
- __t.__t_ = 0;
+ __t.__t_ = _LIBCPP_NULL_THREAD;
return *this;
}
Index: include/__threading_support
===================================================================
--- include/__threading_support
+++ include/__threading_support
@@ -61,6 +61,8 @@
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 DWORD __libcpp_thread_id;
// Thread
+#define _LIBCPP_NULL_THREAD 0U
+
typedef HANDLE __libcpp_thread_t;
// Thread Local Storage
@@ -158,6 +162,9 @@
// 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 @@
}
// 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 @@
return reinterpret_cast<unsigned int>(data.__func(data.__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)
{
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28608.84114.patch
Type: text/x-patch
Size: 2741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170112/6f1d4340/attachment.bin>
More information about the cfe-commits
mailing list