[openssl.org #3196] Default CRYPTO_THREADID for Mac OS X with Posix Threads

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[openssl.org #3196] Default CRYPTO_THREADID for Mac OS X with Posix Threads

Rich Salz via RT
Default CRYPTO_THREADID for Mac OS X with Posix Threads

$ git diff crypto/thr_id.c
diff --git a/crypto/thr_id.c b/crypto/thr_id.c
index 4267526..3b4dc6d 100644
--- a/crypto/thr_id.c
+++ b/crypto/thr_id.c
@@ -116,6 +116,11 @@

 #include "cryptlib.h"

+/* OS X way to determine pthread availability. See pthread.h comments */
+#if defined(OPENSSL_SYS_MACOSX) && defined(_POSIX_THREADS)
+# include <pthread.h>
+#endif
+
 #ifndef OPENSSL_NO_DEPRECATED
 static unsigned long (MS_FAR *id_callback)(void)=0;
 #endif
@@ -180,6 +185,13 @@ void (*CRYPTO_THREADID_get_callback(void))(CRYPTO_THREADID
        return threadid_callback;
        }

+#if defined(OPENSSL_SYS_MACOSX) && defined(_POSIX_THREADS)
+static unsigned long CRYPTO_THREADID_macosx_default(void)
+{
+    return (unsigned long)pthread_mach_thread_np(pthread_self());
+}
+#endif
+
 void CRYPTO_THREADID_current(CRYPTO_THREADID *id)
        {
        if (threadid_callback)
@@ -202,6 +214,8 @@ void CRYPTO_THREADID_current(CRYPTO_THREADID *id)
        CRYPTO_THREADID_set_numeric(id, (unsigned long)GetCurrentThreadId());
 #elif defined(OPENSSL_SYS_BEOS)
        CRYPTO_THREADID_set_numeric(id, (unsigned long)find_thread(NULL));
+#elif defined(OPENSSL_SYS_MACOSX) && defined(_POSIX_THREADS)
+       CRYPTO_THREADID_set_numeric(id, CRYPTO_THREADID_macosx_default());
 #else
        /* For everything else, default to using the address of 'errno' */
        CRYPTO_THREADID_set_pointer(id, (void*)&errno);
@@ -244,6 +258,8 @@ unsigned long CRYPTO_thread_id(void)
                ret=(unsigned long)GetCurrentTask();
 #elif defined(OPENSSL_SYS_WIN32)
                ret=(unsigned long)GetCurrentThreadId();
+#elif defined(OPENSSL_SYS_MACOSX) && defined(_POSIX_THREADS)
+               ret=CRYPTO_THREADID_macosx_default();
 #elif defined(GETPID_IS_MEANINGLESS)
                ret=1L;
 #elif defined(OPENSSL_SYS_BEOS)


thr_id.c.patch (2K) Download Attachment