summaryrefslogtreecommitdiffstats
path: root/libcxx/include/__threading_support
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2019-08-14 16:21:27 +0000
committerMarshall Clow <mclow.lists@gmail.com>2019-08-14 16:21:27 +0000
commit2b1d42541f20ce919c7841328934f64366e39d7c (patch)
tree34344f7fe94faf4de6f5cb6574be9328b5ee3a65 /libcxx/include/__threading_support
parent2be59170d433be05204992838a1aadbc79d5e0d1 (diff)
downloadbcm5719-llvm-2b1d42541f20ce919c7841328934f64366e39d7c.tar.gz
bcm5719-llvm-2b1d42541f20ce919c7841328934f64366e39d7c.zip
Rework recursive_timed_mutex so that it uses __thread_id instead of using the lower-level __libcpp_thread_id. This is prep for fixing PR42918. Reviewed as https://reviews.llvm.org/D65895
llvm-svn: 368867
Diffstat (limited to 'libcxx/include/__threading_support')
-rw-r--r--libcxx/include/__threading_support73
1 files changed, 73 insertions, 0 deletions
diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support
index 589fe2096fd..29a29075da1 100644
--- a/libcxx/include/__threading_support
+++ b/libcxx/include/__threading_support
@@ -12,6 +12,7 @@
#include <__config>
#include <chrono>
+#include <iosfwd>
#include <errno.h>
#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
@@ -394,6 +395,78 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
#endif // !_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL || _LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL
+class _LIBCPP_TYPE_VIS thread;
+class _LIBCPP_TYPE_VIS __thread_id;
+
+namespace this_thread
+{
+
+_LIBCPP_INLINE_VISIBILITY __thread_id get_id() _NOEXCEPT;
+
+} // this_thread
+
+template<> struct hash<__thread_id>;
+
+class _LIBCPP_TEMPLATE_VIS __thread_id
+{
+ // FIXME: pthread_t is a pointer on Darwin but a long on Linux.
+ // NULL is the no-thread value on Darwin. Someone needs to check
+ // 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
+ {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
+ {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);}
+
+ _LIBCPP_INLINE_VISIBILITY
+ void reset() { __id_ = 0; }
+
+ template<class _CharT, class _Traits>
+ friend
+ _LIBCPP_INLINE_VISIBILITY
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id);
+
+private:
+ _LIBCPP_INLINE_VISIBILITY
+ __thread_id(__libcpp_thread_id __id) : __id_(__id) {}
+
+ friend __thread_id this_thread::get_id() _NOEXCEPT;
+ friend class _LIBCPP_TYPE_VIS thread;
+ friend struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>;
+};
+
+namespace this_thread
+{
+
+inline _LIBCPP_INLINE_VISIBILITY
+__thread_id
+get_id() _NOEXCEPT
+{
+ return __libcpp_thread_get_current_id();
+}
+
+} // this_thread
+
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
OpenPOWER on IntegriCloud