[libcxx-commits] [PATCH] D88599: [SystemZ][ZOS] Porting pthread_t related functionality within libc++ to z/OS

Zbigniew Sarbinowski via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 30 10:51:40 PDT 2020


zibi created this revision.
zibi added reviewers: uweigand, hubert.reinterpretcast, ldionne, SeanP, xingxue.
zibi added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
zibi requested review of this revision.

This patch will address the differences of definition of pthread_t on z/OS vs. Linux.
Main trick to make the code work on z/OS relies on redefining __libcpp_thread_id type and
_LIBCPP_NULL_THREAD macro. This is necessary to separate initialization of __libcxx_thread_id from the one of __libcxx_thread_t;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88599

Files:
  libcxx/include/__config
  libcxx/include/__threading_support


Index: libcxx/include/__threading_support
===================================================================
--- libcxx/include/__threading_support
+++ libcxx/include/__threading_support
@@ -26,7 +26,7 @@
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 # include <pthread.h>
 # include <sched.h>
-# ifdef __APPLE__
+# if defined(__APPLE__) || defined(__MVS__)
 #  define _LIBCPP_NO_NATIVE_SEMAPHORES
 # endif
 # ifndef _LIBCPP_NO_NATIVE_SEMAPHORES
@@ -82,10 +82,18 @@
 #define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
 
 // Thread id
-typedef pthread_t __libcpp_thread_id;
+#if defined(__MVS__)
+  typedef unsigned long long __libcpp_thread_id;
+#else
+  typedef pthread_t __libcpp_thread_id;
+#endif
 
 // Thread
-#define _LIBCPP_NULL_THREAD 0U
+#if defined(__MVS__)
+  #define _LIBCPP_NULL_THREAD (__libcpp_thread_t())
+#else
+  #define _LIBCPP_NULL_THREAD 0U
+#endif
 
 typedef pthread_t __libcpp_thread_t;
 
@@ -484,7 +492,7 @@
 // Returns non-zero if the thread ids are equal, otherwise 0
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
 {
-  return pthread_equal(t1, t2) != 0;
+  return t1 == t2;
 }
 
 // Returns non-zero if t1 < t2, otherwise 0
@@ -495,7 +503,7 @@
 
 // Thread
 bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
-  return *__t == 0;
+  return __libcpp_thread_get_id(__t) == 0;
 }
 
 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
@@ -506,12 +514,17 @@
 
 __libcpp_thread_id __libcpp_thread_get_current_id()
 {
-  return pthread_self();
+  const __libcpp_thread_t thread = pthread_self();
+  return __libcpp_thread_get_id(&thread);
 }
 
 __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t)
 {
+#if defined(__MVS__)
+  return __t->__;
+#else
   return *__t;
+#endif
 }
 
 int __libcpp_thread_join(__libcpp_thread_t *__t)
Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -1129,6 +1129,7 @@
       defined(__APPLE__) || \
       defined(__CloudABI__) || \
       defined(__sun__) || \
+      defined(__MVS__) || \
       (defined(__MINGW32__) && __has_include(<pthread.h>))
 #    define _LIBCPP_HAS_THREAD_API_PTHREAD
 #  elif defined(__Fuchsia__)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88599.295349.patch
Type: text/x-patch
Size: 2272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200930/68850108/attachment.bin>


More information about the libcxx-commits mailing list