diff options
author | David Benjamin <davidben@google.com> | 2016-09-21 00:35:09 +0300 |
---|---|---|
committer | CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org> | 2016-09-21 01:25:14 +0300 |
commit | 84759bd4afbfc5b177d0014295dc1bb58ed90fe0 (patch) | |
tree | cd89a8402f0ae1a2cd994f8bfc94d21afda4a945 | |
parent | f12320a78cacb4b16e3ec7d59d53757b7a80a9ef (diff) |
Use pthreads on MinGW.
Android uses MinGW for some host tools on Windows. That toolchain
doesn't support the #pragma tricks we use for thread-local destructors,
but does appear to support pthreads.
This also lets us remove the INIT_ONCE workaround, although that's
removable anyway since Android's MinGW is now new enough.
Change-Id: I8d1573923fdaac880a50d84acbebbf87461c50d2
Reviewed-on: https://boringssl-review.googlesource.com/11125
Reviewed-by: David Benjamin <davidben@google.com>
Reviewed-by: Kenny Root <kroot@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
-rw-r--r-- | crypto/internal.h | 35 | ||||
-rw-r--r-- | crypto/thread_pthread.c | 4 | ||||
-rw-r--r-- | crypto/thread_win.c | 4 |
3 files changed, 21 insertions, 22 deletions
diff --git a/crypto/internal.h b/crypto/internal.h index d6e341a5..8ac60cbd 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -121,13 +121,18 @@ #include <stdalign.h> #endif -#if defined(OPENSSL_NO_THREADS) -#elif defined(OPENSSL_WINDOWS) +#if !defined(OPENSSL_NO_THREADS) && \ + (!defined(OPENSSL_WINDOWS) || defined(__MINGW32__)) +#include <pthread.h> +#define OPENSSL_PTHREADS +#endif + +#if !defined(OPENSSL_NO_THREADS) && !defined(OPENSSL_PTHREADS) && \ + defined(OPENSSL_WINDOWS) +#define OPENSSL_WINDOWS_THREADS OPENSSL_MSVC_PRAGMA(warning(push, 3)) #include <windows.h> OPENSSL_MSVC_PRAGMA(warning(pop)) -#else -#include <pthread.h> #endif #if defined(__cplusplus) @@ -304,25 +309,17 @@ static inline int constant_time_select_int(unsigned int mask, int a, int b) { /* Thread-safe initialisation. */ -/* Android's mingw-w64 has some prototypes for INIT_ONCE, but is missing - * others. Work around the missing ones. - * - * TODO(davidben): Remove this once Android's mingw-w64 is upgraded. See - * b/26523949. */ -#if defined(__MINGW32__) && !defined(INIT_ONCE_STATIC_INIT) -typedef RTL_RUN_ONCE INIT_ONCE; -#define INIT_ONCE_STATIC_INIT RTL_RUN_ONCE_INIT -#endif - #if defined(OPENSSL_NO_THREADS) typedef uint32_t CRYPTO_once_t; #define CRYPTO_ONCE_INIT 0 -#elif defined(OPENSSL_WINDOWS) +#elif defined(OPENSSL_WINDOWS_THREADS) typedef INIT_ONCE CRYPTO_once_t; #define CRYPTO_ONCE_INIT INIT_ONCE_STATIC_INIT -#else +#elif defined(OPENSSL_PTHREADS) typedef pthread_once_t CRYPTO_once_t; #define CRYPTO_ONCE_INIT PTHREAD_ONCE_INIT +#else +#error "Unknown threading library" #endif /* CRYPTO_once calls |init| exactly once per process. This is thread-safe: if @@ -373,16 +370,18 @@ struct CRYPTO_STATIC_MUTEX { char padding; /* Empty structs have different sizes in C and C++. */ }; #define CRYPTO_STATIC_MUTEX_INIT { 0 } -#elif defined(OPENSSL_WINDOWS) +#elif defined(OPENSSL_WINDOWS_THREADS) struct CRYPTO_STATIC_MUTEX { SRWLOCK lock; }; #define CRYPTO_STATIC_MUTEX_INIT { SRWLOCK_INIT } -#else +#elif defined(OPENSSL_PTHREADS) struct CRYPTO_STATIC_MUTEX { pthread_rwlock_t lock; }; #define CRYPTO_STATIC_MUTEX_INIT { PTHREAD_RWLOCK_INITIALIZER } +#else +#error "Unknown threading library" #endif /* CRYPTO_MUTEX_init initialises |lock|. If |lock| is a static variable, use a diff --git a/crypto/thread_pthread.c b/crypto/thread_pthread.c index 2baa2b4d..90ff861e 100644 --- a/crypto/thread_pthread.c +++ b/crypto/thread_pthread.c @@ -14,7 +14,7 @@ #include "internal.h" -#if !defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_THREADS) +#if defined(OPENSSL_PTHREADS) #include <pthread.h> #include <stdlib.h> @@ -173,4 +173,4 @@ int CRYPTO_set_thread_local(thread_local_data_t index, void *value, return 1; } -#endif /* !OPENSSL_WINDOWS && !OPENSSL_NO_THREADS */ +#endif /* OPENSSL_PTHREADS */ diff --git a/crypto/thread_win.c b/crypto/thread_win.c index c7a90f7e..836cf0f2 100644 --- a/crypto/thread_win.c +++ b/crypto/thread_win.c @@ -14,7 +14,7 @@ #include "internal.h" -#if defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_THREADS) +#if defined(OPENSSL_WINDOWS_THREADS) OPENSSL_MSVC_PRAGMA(warning(push, 3)) #include <windows.h> @@ -234,4 +234,4 @@ int CRYPTO_set_thread_local(thread_local_data_t index, void *value, return 1; } -#endif /* OPENSSL_WINDOWS && !OPENSSL_NO_THREADS */ +#endif /* OPENSSL_WINDOWS_THREADS */ |