From a5d6fda4338641a64d07b353129e5731a6517941 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 27 Jul 2021 23:14:01 +0100 Subject: Define which mutexes are blocking and recursive explicitly --- src/common.cpp | 96 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 38 deletions(-) (limited to 'src/common.cpp') diff --git a/src/common.cpp b/src/common.cpp index 0e11ed5a6..8a51bbcb5 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -29,6 +29,64 @@ #include #include // Because I wanted the C++11 memory order semantics, of which gb.h does not offer (because it was a C89 library) + +#if defined(GB_SYSTEM_WINDOWS) + struct BlockingMutex { + SRWLOCK srwlock; + }; + void mutex_init(BlockingMutex *m) { + } + void mutex_destroy(BlockingMutex *m) { + } + void mutex_lock(BlockingMutex *m) { + AcquireSRWLockExclusive(&m->srwlock); + } + bool mutex_try_lock(BlockingMutex *m) { + return !!TryAcquireSRWLockExclusive(&m->srwlock); + } + void mutex_unlock(BlockingMutex *m) { + ReleaseSRWLockExclusive(&m->srwlock); + } +#else + typedef gbMutex BlockingMutex; + void mutex_init(BlockingMutex *m) { + gb_mutex_init(m); + } + void mutex_destroy(BlockingMutex *m) { + gb_mutex_destroy(m); + } + void mutex_lock(BlockingMutex *m) { + gb_mutex_lock(m); + } + bool mutex_try_lock(BlockingMutex *m) { + return !!gb_mutex_try_lock(m); + } + void mutex_unlock(BlockingMutex *m) { + gb_mutex_unlock(m); + } +#endif + +struct RecursiveMutex { + gbMutex mutex; +}; +void mutex_init(RecursiveMutex *m) { + gb_mutex_init(&m->mutex); +} +void mutex_destroy(RecursiveMutex *m) { + gb_mutex_destroy(&m->mutex); +} +void mutex_lock(RecursiveMutex *m) { + gb_mutex_lock(&m->mutex); +} +bool mutex_try_lock(RecursiveMutex *m) { + return gb_mutex_try_lock(&m->mutex); +} +void mutex_unlock(RecursiveMutex *m) { + gb_mutex_unlock(&m->mutex); +} + + + gb_inline void zero_size(void *ptr, isize len) { memset(ptr, 0, len); } @@ -1300,41 +1358,3 @@ Slice did_you_mean_results(DidYouMeanAnswers *d) { } return slice_array(d->distances, 0, count); } - - - -#if defined(GB_SYSTEM_WINDOWS) - struct BlockingMutex { - SRWLOCK srwlock; - }; - void mutex_init(BlockingMutex *m) { - } - void mutex_destroy(BlockingMutex *m) { - } - void mutex_lock(BlockingMutex *m) { - AcquireSRWLockExclusive(&m->srwlock); - } - bool mutex_try_lock(BlockingMutex *m) { - return !!TryAcquireSRWLockExclusive(&m->srwlock); - } - void mutex_unlock(BlockingMutex *m) { - ReleaseSRWLockExclusive(&m->srwlock); - } -#else - typedef gbMutex BlockingMutex; - void mutex_init(BlockingMutex *m) { - gb_mutex_init(m); - } - void mutex_destroy(BlockingMutex *m) { - gb_mutex_destroy(m); - } - void mutex_lock(BlockingMutex *m) { - gb_mutex_lock(m); - } - bool mutex_try_lock(BlockingMutex *m) { - return !!gb_mutex_try_lock(m); - } - void mutex_unlock(BlockingMutex *m) { - gb_mutex_unlock(m); - } -#endif -- cgit v1.2.3