diff options
author | sanine <sanine.not@pm.me> | 2022-08-26 12:17:51 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-08-26 12:17:51 -0500 |
commit | 8ec3f8e82acd70410515550fd1790ee5827aafdb (patch) | |
tree | 348e32b7fe2f0e765d3acf91fa857880d8f6c3f6 /src/mossrose-mutex.c | |
parent | a20cdab55ba066301da138c4df945608524e741a (diff) |
make sound
Diffstat (limited to 'src/mossrose-mutex.c')
-rw-r--r-- | src/mossrose-mutex.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/mossrose-mutex.c b/src/mossrose-mutex.c new file mode 100644 index 0000000..b6865f8 --- /dev/null +++ b/src/mossrose-mutex.c @@ -0,0 +1,58 @@ +#include "mossrose-mutex.h" + +#ifdef WIN32 +#include <windows.h> +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 <pthread.h> +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 |