From: Nadav Har'El <n...@scylladb.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

pthread: change type of pthread_t

Our pthread_t type was a pointer, while in Linux it was an unsigned long.
This was ok for binary compatibility, because both have the same size,
but the unnecessary difference can cause problems in source code - and
does cause problems for Gcc 6: In Gcc 6's <thread> header file, they
have the code thread::id(1) - which tries to convert the integer 1 into
a pthread_t. This failed when our pthread_t was a pointer.

So this patch trivially changes pthread_t's type to unsigned long, as in
Linux. Nothing else in the code needs to change, because the code always
(see pthread::from_libc) reinterpret_cast's pthread_t, whatever it is,
into a pointer. Additionally, we add a static_assert to verify that these
two types (the pointer and pthread_t) really have the same length, as
intended.

Fixes #770.

Signed-off-by: Nadav Har'El <n...@scylladb.com>
Message-Id: <1469050999-10574-1-git-send-email-...@scylladb.com>

---
diff --git a/include/api/aarch64/bits/alltypes.h.sh b/include/api/aarch64/bits/alltypes.h.sh
--- a/include/api/aarch64/bits/alltypes.h.sh
+++ b/include/api/aarch64/bits/alltypes.h.sh
@@ -83,7 +83,7 @@ TYPEDEF unsigned int uid_t;
 TYPEDEF unsigned int gid_t;
 TYPEDEF int key_t;

-TYPEDEF struct __pthread * pthread_t;
+TYPEDEF unsigned long pthread_t;
 TYPEDEF int pthread_once_t;
 TYPEDEF unsigned pthread_key_t;
 TYPEDEF int pthread_spinlock_t;
diff --git a/include/api/x64/bits/alltypes.h.sh b/include/api/x64/bits/alltypes.h.sh
--- a/include/api/x64/bits/alltypes.h.sh
+++ b/include/api/x64/bits/alltypes.h.sh
@@ -82,7 +82,7 @@ TYPEDEF unsigned int uid_t;
 TYPEDEF unsigned int gid_t;
 TYPEDEF int key_t;

-TYPEDEF struct __pthread * pthread_t;
+TYPEDEF unsigned long pthread_t;
 TYPEDEF int pthread_once_t;
 TYPEDEF int pthread_key_t;
 TYPEDEF int pthread_spinlock_t;
diff --git a/libc/pthread.cc b/libc/pthread.cc
--- a/libc/pthread.cc
+++ b/libc/pthread.cc
@@ -149,6 +149,8 @@ namespace pthread_private {

     pthread* pthread::from_libc(pthread_t p)
     {
+        static_assert(sizeof(pthread_t) == sizeof(pthread*),
+            "pthread_t is not the same size as pthread*");
         return reinterpret_cast<pthread*>(p);
     }

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to