diff options
Diffstat (limited to 'src/Platform/Win32/Mutex.c')
| -rw-r--r-- | src/Platform/Win32/Mutex.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Platform/Win32/Mutex.c b/src/Platform/Win32/Mutex.c new file mode 100644 index 0000000..f34aac1 --- /dev/null +++ b/src/Platform/Win32/Mutex.c @@ -0,0 +1,51 @@ +#include "Thread.h" + +#include <BH/Thread.h> + + +BH_Mutex *BH_MutexNew(void) +{ + BH_Mutex *mutex; + + /* Allocate space for mutex and initialize it */ + mutex = malloc(sizeof(BH_Mutex)); + if (mutex && !InitializeCriticalSectionAndSpinCount(&mutex->handle, 0x400)) + { + free(mutex); + return NULL; + } + + return mutex; +} + + +void BH_MutexFree(BH_Mutex *mutex) +{ + DeleteCriticalSection(&mutex->handle); + free(mutex); +} + + +int BH_MutexLock(BH_Mutex *mutex) +{ + EnterCriticalSection(&mutex->handle); + + return BH_OK; +} + + +int BH_MutexUnlock(BH_Mutex *mutex) +{ + LeaveCriticalSection(&mutex->handle); + + return BH_OK; +} + + +int BH_MutexLockTry(BH_Mutex *mutex) +{ + if (!TryEnterCriticalSection(&mutex->handle)) + return BH_ERROR; + + return BH_OK; +} |
