#include "mossrose-mutex.h" #ifdef WIN32 #include void mossrose_mutex_init(mossrose_mutex_t *mutex) { *mutex = CreateMutex(NULL, false, NULL); } void mossrose_mutex_lock(mossrose_mutex_t *mutex) { WaitForSingleObject(*mutex, INFINITE); } int mossrose_mutex_trylock(mossrose_mutex_t *mutex) { int result = WaitForSingleObject(*mutex, 0); return result != WAIT_OBJECT_0; } void mossrose_mutex_unlock(mossrose_mutex_t *mutex) { ReleaseMutex(*mutex); } void mossrose_mutex_destroy(mossrose_mutex_t *mutex) { ReleaseMutex(*mutex); } #else #include void mossrose_mutex_init(mossrose_mutex_t *mutex) { pthread_mutex_init(mutex, NULL); } void mossrose_mutex_lock(mossrose_mutex_t *mutex) { pthread_mutex_lock(mutex); } int mossrose_mutex_trylock(mossrose_mutex_t *mutex) { return pthread_mutex_trylock(mutex); } void mossrose_mutex_unlock(mossrose_mutex_t *mutex) { pthread_mutex_unlock(mutex); } void mossrose_mutex_destroy(mossrose_mutex_t *mutex) { pthread_mutex_destroy(mutex); } #endif