# HG changeset patch # User Benjamin Barenblat # Date 1442785567 14400 # Node ID ce312cad5ecda7469be0e35657dcb2305e84fef0 # Parent 010ce27228f1894d2adc7672d11b39131ab91f47 Use correct OpenSSL thread safety macros on OS X (closes #209) Create an Autoconf test to determine if pthread_t is a pointer or scalar type, and use the appropriate CRYPTO_THREADID_set macro based on the result. diff -r 010ce27228f1 -r ce312cad5ecd configure.ac --- a/configure.ac Thu Aug 27 16:28:45 2015 -0400 +++ b/configure.ac Sun Sep 20 17:46:07 2015 -0400 @@ -112,6 +112,22 @@ PTHREAD_LIBS="" fi +# Check if pthread_t is a scalar or pointer type so we can use the correct +# OpenSSL functions on it. +AC_MSG_CHECKING([if pthread_t is a pointer type]) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include + ]], + [[ +pthread_t a; +*a; + ]])], + AC_DEFINE([PTHREAD_T_IS_POINTER], [1], [Define if pthread_t is a pointer.]) + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(CC) AC_SUBST(BIN) AC_SUBST(LIB) diff -r 010ce27228f1 -r ce312cad5ecd src/c/openssl.c --- a/src/c/openssl.c Thu Aug 27 16:28:45 2015 -0400 +++ b/src/c/openssl.c Sun Sep 20 17:46:07 2015 -0400 @@ -34,9 +34,15 @@ } // OpenSSL callbacks +#ifdef PTHREAD_T_IS_POINTER +# define CRYPTO_THREADID_SET CRYPTO_THREADID_set_pointer +#else +# define CRYPTO_THREADID_SET CRYPTO_THREADID_set_numeric +#endif static void thread_id(CRYPTO_THREADID *const result) { - CRYPTO_THREADID_set_numeric(result, pthread_self()); + CRYPTO_THREADID_SET(result, pthread_self()); } +#undef CRYPTO_THREADID_SET static void lock_or_unlock(const int mode, const int type, const char *file, const int line) { pthread_mutex_t *const lock = &openssl_locks[type];