mirror of
https://github.com/Jous99/F4MP.git
synced 2026-01-13 00:40:53 +01:00
50 lines
1.1 KiB
C
50 lines
1.1 KiB
C
|
|
// file: source/threading/mutex.c
|
||
|
|
|
||
|
|
#ifdef ZPL_EDITOR
|
||
|
|
#include <zpl.h>
|
||
|
|
#endif
|
||
|
|
|
||
|
|
ZPL_BEGIN_C_DECLS
|
||
|
|
|
||
|
|
void zpl_mutex_init(zpl_mutex *m) {
|
||
|
|
#if defined(ZPL_SYSTEM_WINDOWS)
|
||
|
|
InitializeCriticalSection(&m->win32_critical_section);
|
||
|
|
#else
|
||
|
|
pthread_mutex_init(&m->pthread_mutex, NULL);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
void zpl_mutex_destroy(zpl_mutex *m) {
|
||
|
|
#if defined(ZPL_SYSTEM_WINDOWS)
|
||
|
|
DeleteCriticalSection(&m->win32_critical_section);
|
||
|
|
#else
|
||
|
|
pthread_mutex_destroy(&m->pthread_mutex);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
void zpl_mutex_lock(zpl_mutex *m) {
|
||
|
|
#if defined(ZPL_SYSTEM_WINDOWS)
|
||
|
|
EnterCriticalSection(&m->win32_critical_section);
|
||
|
|
#else
|
||
|
|
pthread_mutex_lock(&m->pthread_mutex);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
zpl_b32 zpl_mutex_try_lock(zpl_mutex *m) {
|
||
|
|
#if defined(ZPL_SYSTEM_WINDOWS)
|
||
|
|
return TryEnterCriticalSection(&m->win32_critical_section);
|
||
|
|
#else
|
||
|
|
return pthread_mutex_trylock(&m->pthread_mutex);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
void zpl_mutex_unlock(zpl_mutex *m) {
|
||
|
|
#if defined(ZPL_SYSTEM_WINDOWS)
|
||
|
|
LeaveCriticalSection(&m->win32_critical_section);
|
||
|
|
#else
|
||
|
|
pthread_mutex_unlock(&m->pthread_mutex);
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
ZPL_END_C_DECLS
|