diff options
-rw-r--r-- | librabbitmq/amqp_openssl.c | 21 | ||||
-rw-r--r-- | librabbitmq/win32/threads.c | 33 | ||||
-rw-r--r-- | librabbitmq/win32/threads.h | 8 |
3 files changed, 16 insertions, 46 deletions
diff --git a/librabbitmq/amqp_openssl.c b/librabbitmq/amqp_openssl.c index 333c7ed..d7ff38d 100644 --- a/librabbitmq/amqp_openssl.c +++ b/librabbitmq/amqp_openssl.c @@ -59,12 +59,8 @@ static amqp_boolean_t openssl_initialized = 0; static unsigned long amqp_ssl_threadid_callback(void); static void amqp_ssl_locking_callback(int mode, int n, const char *file, int line); -#ifdef _WIN32 -static long win32_create_mutex = 0; -static pthread_mutex_t openssl_init_mutex = NULL; -#else static pthread_mutex_t openssl_init_mutex = PTHREAD_MUTEX_INITIALIZER; -#endif + static pthread_mutex_t *amqp_openssl_lockarray = NULL; #endif /* ENABLE_THREAD_SAFETY */ @@ -600,21 +596,6 @@ static int initialize_openssl(void) { #ifdef ENABLE_THREAD_SAFETY -#ifdef _WIN32 - /* No such thing as PTHREAD_INITIALIZE_MUTEX macro on Win32, so we use this */ - if (NULL == openssl_init_mutex) { - while (InterlockedExchange(&win32_create_mutex, 1) == 1) - /* Loop, someone else is holding this lock */ ; - - if (NULL == openssl_init_mutex) { - if (pthread_mutex_init(&openssl_init_mutex, NULL)) { - return -1; - } - } - InterlockedExchange(&win32_create_mutex, 0); - } -#endif /* _WIN32 */ - if (pthread_mutex_lock(&openssl_init_mutex)) { return -1; } diff --git a/librabbitmq/win32/threads.c b/librabbitmq/win32/threads.c index 60f00b3..49257cc 100644 --- a/librabbitmq/win32/threads.c +++ b/librabbitmq/win32/threads.c @@ -25,41 +25,28 @@ #include <stdlib.h> -DWORD -pthread_self(void) -{ - return GetCurrentThreadId(); -} +DWORD pthread_self(void) { return GetCurrentThreadId(); } -int -pthread_mutex_init(pthread_mutex_t *mutex, void *attr) -{ - *mutex = malloc(sizeof(CRITICAL_SECTION)); - if (!*mutex) { +int pthread_mutex_init(pthread_mutex_t *mutex, void *attr) { + if (!mutex) { return 1; } - InitializeCriticalSection(*mutex); + InitializeSRWLock(mutex); return 0; } -int -pthread_mutex_lock(pthread_mutex_t *mutex) -{ - if (!*mutex) { +int pthread_mutex_lock(pthread_mutex_t *mutex) { + if (!mutex) { return 1; } - - EnterCriticalSection(*mutex); + AcquireSRWLockExclusive(mutex); return 0; } -int -pthread_mutex_unlock(pthread_mutex_t *mutex) -{ - if (!*mutex) { +int pthread_mutex_unlock(pthread_mutex_t *mutex) { + if (!mutex) { return 1; } - - LeaveCriticalSection(*mutex); + ReleaseSRWLockExclusive(mutex); return 0; } diff --git a/librabbitmq/win32/threads.h b/librabbitmq/win32/threads.h index 1d1c53f..9a17598 100644 --- a/librabbitmq/win32/threads.h +++ b/librabbitmq/win32/threads.h @@ -29,19 +29,21 @@ #define AMQP_THREAD_H #ifndef WINVER -# define WINVER 0x0502 + /* Windows Vista or newer */ +# define WINVER 0x0600 #endif #ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN #endif #include <windows.h> -typedef CRITICAL_SECTION *pthread_mutex_t; -typedef int pthread_once_t; +typedef SRWLOCK pthread_mutex_t; +#define PTHREAD_MUTEX_INITIALIZER SRWLOCK_INIT; DWORD pthread_self(void); int pthread_mutex_init(pthread_mutex_t *, void *attr); int pthread_mutex_lock(pthread_mutex_t *); int pthread_mutex_unlock(pthread_mutex_t *); + #endif /* AMQP_THREAD_H */ |