File indexing completed on 2026-05-03 08:14:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___THREAD_ID_H
0011 #define _LIBCPP___THREAD_ID_H
0012
0013 #include <__compare/ordering.h>
0014 #include <__config>
0015 #include <__fwd/functional.h>
0016 #include <__fwd/ostream.h>
0017 #include <__thread/support.h>
0018
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 # pragma GCC system_header
0021 #endif
0022
0023 _LIBCPP_BEGIN_NAMESPACE_STD
0024
0025 #if _LIBCPP_HAS_THREADS
0026 class _LIBCPP_EXPORTED_FROM_ABI __thread_id;
0027
0028 namespace this_thread {
0029
0030 _LIBCPP_HIDE_FROM_ABI __thread_id get_id() _NOEXCEPT;
0031
0032 }
0033
0034 template <>
0035 struct hash<__thread_id>;
0036
0037 class _LIBCPP_TEMPLATE_VIS __thread_id {
0038
0039
0040
0041 __libcpp_thread_id __id_;
0042
0043 static _LIBCPP_HIDE_FROM_ABI bool
0044 __lt_impl(__thread_id __x, __thread_id __y) _NOEXCEPT {
0045 if (__x.__id_ == 0)
0046 return __y.__id_ != 0;
0047 if (__y.__id_ == 0)
0048 return false;
0049 return __libcpp_thread_id_less(__x.__id_, __y.__id_);
0050 }
0051
0052 public:
0053 _LIBCPP_HIDE_FROM_ABI __thread_id() _NOEXCEPT : __id_(0) {}
0054
0055 _LIBCPP_HIDE_FROM_ABI void __reset() { __id_ = 0; }
0056
0057 friend _LIBCPP_HIDE_FROM_ABI bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT;
0058 # if _LIBCPP_STD_VER <= 17
0059 friend _LIBCPP_HIDE_FROM_ABI bool operator<(__thread_id __x, __thread_id __y) _NOEXCEPT;
0060 # else
0061 friend _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(__thread_id __x, __thread_id __y) noexcept;
0062 # endif
0063
0064 template <class _CharT, class _Traits>
0065 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0066 operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id);
0067
0068 private:
0069 _LIBCPP_HIDE_FROM_ABI __thread_id(__libcpp_thread_id __id) : __id_(__id) {}
0070
0071 _LIBCPP_HIDE_FROM_ABI friend __libcpp_thread_id __get_underlying_id(const __thread_id __id) { return __id.__id_; }
0072
0073 friend __thread_id this_thread::get_id() _NOEXCEPT;
0074 friend class _LIBCPP_EXPORTED_FROM_ABI thread;
0075 friend struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>;
0076 };
0077
0078 inline _LIBCPP_HIDE_FROM_ABI bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT {
0079
0080 if (__x.__id_ == 0)
0081 return __y.__id_ == 0;
0082 if (__y.__id_ == 0)
0083 return false;
0084 return __libcpp_thread_id_equal(__x.__id_, __y.__id_);
0085 }
0086
0087 # if _LIBCPP_STD_VER <= 17
0088
0089 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(__thread_id __x, __thread_id __y) _NOEXCEPT { return !(__x == __y); }
0090
0091 inline _LIBCPP_HIDE_FROM_ABI bool operator<(__thread_id __x, __thread_id __y) _NOEXCEPT {
0092 return __thread_id::__lt_impl(__x.__id_, __y.__id_);
0093 }
0094
0095 inline _LIBCPP_HIDE_FROM_ABI bool operator<=(__thread_id __x, __thread_id __y) _NOEXCEPT { return !(__y < __x); }
0096 inline _LIBCPP_HIDE_FROM_ABI bool operator>(__thread_id __x, __thread_id __y) _NOEXCEPT { return __y < __x; }
0097 inline _LIBCPP_HIDE_FROM_ABI bool operator>=(__thread_id __x, __thread_id __y) _NOEXCEPT { return !(__x < __y); }
0098
0099 # else
0100
0101 inline _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(__thread_id __x, __thread_id __y) noexcept {
0102 if (__x == __y)
0103 return strong_ordering::equal;
0104 if (__thread_id::__lt_impl(__x, __y))
0105 return strong_ordering::less;
0106 return strong_ordering::greater;
0107 }
0108
0109 # endif
0110
0111 namespace this_thread {
0112
0113 inline _LIBCPP_HIDE_FROM_ABI __thread_id get_id() _NOEXCEPT { return __libcpp_thread_get_current_id(); }
0114
0115 }
0116
0117 #endif
0118
0119 _LIBCPP_END_NAMESPACE_STD
0120
0121 #endif