aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/__threading_support
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/__threading_support')
-rw-r--r--libcxx/include/__threading_support79
1 files changed, 54 insertions, 25 deletions
diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support
index a7f0da972a8d..dcf2763ad646 100644
--- a/libcxx/include/__threading_support
+++ b/libcxx/include/__threading_support
@@ -13,7 +13,9 @@
#include <__availability>
#include <__chrono/convert_to_timespec.h>
#include <__chrono/duration.h>
+#include <__compare/ordering.h>
#include <__config>
+#include <__fwd/hash.h>
#include <__thread/poll_with_backoff.h>
#include <errno.h>
#include <iosfwd>
@@ -609,40 +611,28 @@ class _LIBCPP_TEMPLATE_VIS __thread_id
// on other platforms. We assume 0 works everywhere for now.
__libcpp_thread_id __id_;
-public:
- _LIBCPP_INLINE_VISIBILITY
- __thread_id() _NOEXCEPT : __id_(0) {}
-
- friend _LIBCPP_INLINE_VISIBILITY
- bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT
- { // don't pass id==0 to underlying routines
- if (__x.__id_ == 0) return __y.__id_ == 0;
- if (__y.__id_ == 0) return false;
- return __libcpp_thread_id_equal(__x.__id_, __y.__id_);
- }
- friend _LIBCPP_INLINE_VISIBILITY
- bool operator!=(__thread_id __x, __thread_id __y) _NOEXCEPT
- {return !(__x == __y);}
- friend _LIBCPP_INLINE_VISIBILITY
- bool operator< (__thread_id __x, __thread_id __y) _NOEXCEPT
+ static _LIBCPP_HIDE_FROM_ABI
+ bool __lt_impl(__thread_id __x, __thread_id __y) _NOEXCEPT
{ // id==0 is always less than any other thread_id
if (__x.__id_ == 0) return __y.__id_ != 0;
if (__y.__id_ == 0) return false;
return __libcpp_thread_id_less(__x.__id_, __y.__id_);
}
- friend _LIBCPP_INLINE_VISIBILITY
- bool operator<=(__thread_id __x, __thread_id __y) _NOEXCEPT
- {return !(__y < __x);}
- friend _LIBCPP_INLINE_VISIBILITY
- bool operator> (__thread_id __x, __thread_id __y) _NOEXCEPT
- {return __y < __x ;}
- friend _LIBCPP_INLINE_VISIBILITY
- bool operator>=(__thread_id __x, __thread_id __y) _NOEXCEPT
- {return !(__x < __y);}
+
+public:
+ _LIBCPP_INLINE_VISIBILITY
+ __thread_id() _NOEXCEPT : __id_(0) {}
_LIBCPP_INLINE_VISIBILITY
void __reset() { __id_ = 0; }
+ friend _LIBCPP_HIDE_FROM_ABI bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT;
+#if _LIBCPP_STD_VER <= 17
+ friend _LIBCPP_HIDE_FROM_ABI bool operator<(__thread_id __x, __thread_id __y) _NOEXCEPT;
+#else // _LIBCPP_STD_VER <= 17
+ friend _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(__thread_id __x, __thread_id __y) noexcept;
+#endif // _LIBCPP_STD_VER <= 17
+
template<class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
@@ -658,6 +648,45 @@ private:
friend struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>;
};
+inline _LIBCPP_HIDE_FROM_ABI
+bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT {
+ // Don't pass id==0 to underlying routines
+ if (__x.__id_ == 0)
+ return __y.__id_ == 0;
+ if (__y.__id_ == 0)
+ return false;
+ return __libcpp_thread_id_equal(__x.__id_, __y.__id_);
+}
+
+#if _LIBCPP_STD_VER <= 17
+
+inline _LIBCPP_HIDE_FROM_ABI
+bool operator!=(__thread_id __x, __thread_id __y) _NOEXCEPT {
+ return !(__x == __y);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI
+bool operator<(__thread_id __x, __thread_id __y) _NOEXCEPT {
+ return __thread_id::__lt_impl(__x.__id_, __y.__id_);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI bool operator<=(__thread_id __x, __thread_id __y) _NOEXCEPT { return !(__y < __x); }
+inline _LIBCPP_HIDE_FROM_ABI bool operator>(__thread_id __x, __thread_id __y) _NOEXCEPT { return __y < __x; }
+inline _LIBCPP_HIDE_FROM_ABI bool operator>=(__thread_id __x, __thread_id __y) _NOEXCEPT { return !(__x < __y); }
+
+#else // _LIBCPP_STD_VER <= 17
+
+inline _LIBCPP_HIDE_FROM_ABI
+strong_ordering operator<=>(__thread_id __x, __thread_id __y) noexcept {
+ if (__x == __y)
+ return strong_ordering::equal;
+ if (__thread_id::__lt_impl(__x, __y))
+ return strong_ordering::less;
+ return strong_ordering::greater;
+}
+
+#endif // _LIBCPP_STD_VER <= 17
+
namespace this_thread
{