From df586b6104a70115d41ad0354879cb0bc69d4875 Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Tue, 29 May 2012 17:30:23 -0400 Subject: Adding pthread shim for Win32 ENABLE_THREAD_SAFETY --- librabbitmq/win32/threads.c | 37 +++++++++++++++++++++++++++++++++++++ librabbitmq/win32/threads.h | 14 ++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 librabbitmq/win32/threads.c create mode 100644 librabbitmq/win32/threads.h (limited to 'librabbitmq/win32') diff --git a/librabbitmq/win32/threads.c b/librabbitmq/win32/threads.c new file mode 100644 index 0000000..cf2e9ee --- /dev/null +++ b/librabbitmq/win32/threads.c @@ -0,0 +1,37 @@ +#include "threads.h" + +DWORD +pthread_self(void) +{ + return GetCurrentThreadId(); +} + +int +pthread_mutex_init(pthread_mutex_t *mutex, void *attr) +{ + *mutex = malloc(sizeof(CRITICAL_SECTION)); + if (!*mutex) + return 1; + InitializeCriticalSection(*mutex); + return 0; +} + +int +pthread_mutex_lock(pthread_mutex_t *mutex) +{ + if (!*mutex) + return 1; + + EnterCriticalSection(*mutex); + return 0; +} + +int +pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + if (!*mutex) + return 1; + + LeaveCriticalSection(*mutex); + return 0; +} diff --git a/librabbitmq/win32/threads.h b/librabbitmq/win32/threads.h new file mode 100644 index 0000000..7cf6ca5 --- /dev/null +++ b/librabbitmq/win32/threads.h @@ -0,0 +1,14 @@ +#ifndef AMQP_THREAD_H +#define AMQP_THREAD_H + +#include + +typedef CRITICAL_SECTION *pthread_mutex_t; +typedef int pthread_once_t; + +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 */ -- cgit v1.2.1