diff options
author | Alan Antonuk <aega@med.umich.edu> | 2012-05-29 17:30:23 -0400 |
---|---|---|
committer | Alan Antonuk <alan.antonuk@gmail.com> | 2013-04-09 15:35:10 -0700 |
commit | df586b6104a70115d41ad0354879cb0bc69d4875 (patch) | |
tree | 554c7551c0aa3f23065357b1fba6dad9361ac12e /librabbitmq/win32 | |
parent | 9d7caaaadb0f3a9f0124f7cc76112f8645971b66 (diff) | |
download | rabbitmq-c-github-ask-df586b6104a70115d41ad0354879cb0bc69d4875.tar.gz |
Adding pthread shim for Win32 ENABLE_THREAD_SAFETY
Diffstat (limited to 'librabbitmq/win32')
-rw-r--r-- | librabbitmq/win32/threads.c | 37 | ||||
-rw-r--r-- | librabbitmq/win32/threads.h | 14 |
2 files changed, 51 insertions, 0 deletions
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 <Windows.h> + +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 */ |