[PATCH] D20874: [libcxx] Two more threading dependencies

Asiri Rathnayake via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 3 02:09:52 PDT 2016


rmaprath updated this revision to Diff 59507.
rmaprath added a comment.

Added a comment about `~std::thread()` hook.

@EricWF: Gentle ping.


http://reviews.llvm.org/D20874

Files:
  include/__threading_support
  src/thread.cpp

Index: src/thread.cpp
===================================================================
--- src/thread.cpp
+++ src/thread.cpp
@@ -39,8 +39,10 @@
 
 thread::~thread()
 {
+    // custom hook allowing thread implementations to control
+    // the ~std::tread() behavior.
     if (__t_ != 0)
-        terminate();
+        __libcpp_thread_terminate();
 }
 
 void
@@ -133,7 +135,7 @@
             ts.tv_nsec = giga::num - 1;
         }
 
-        while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
+        while (__libcpp_thread_nanosleep(&ts, &ts) == -1 && errno == EINTR)
             ;
     }
 }
Index: include/__threading_support
===================================================================
--- include/__threading_support
+++ include/__threading_support
@@ -22,6 +22,8 @@
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 #include <pthread.h>
 #include <sched.h>
+#include <time.h>
+#include <exception>
 #endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
@@ -156,6 +158,12 @@
 }
 
 inline _LIBCPP_ALWAYS_INLINE
+int __libcpp_thread_nanosleep(const timespec *req, timespec *rem)
+{
+    return nanosleep(req, rem);
+}
+
+inline _LIBCPP_ALWAYS_INLINE
 int __libcpp_thread_join(__libcpp_thread_t* __t)
 {
     return pthread_join(*__t, 0);
@@ -173,6 +181,12 @@
     sched_yield();
 }
 
+inline _LIBCPP_ALWAYS_INLINE
+void __libcpp_thread_terminate()
+{
+    std::terminate();
+}
+
 // Thread local storage
 typedef pthread_key_t __libcpp_tl_key;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20874.59507.patch
Type: text/x-patch
Size: 1440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160603/cc8e8531/attachment.bin>


More information about the cfe-commits mailing list