diff options
| author | gingerBill <bill@gingerbill.org> | 2021-07-27 23:14:01 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-07-27 23:14:01 +0100 |
| commit | a5d6fda4338641a64d07b353129e5731a6517941 (patch) | |
| tree | 0cce749ad561e7a27b3c5eb0d6443f3d58a6df34 /src/common.cpp | |
| parent | 4bc3796f9b9e8ea00ff0da89f6e983345fb2fd7e (diff) | |
Define which mutexes are blocking and recursive explicitly
Diffstat (limited to 'src/common.cpp')
| -rw-r--r-- | src/common.cpp | 96 |
1 files changed, 58 insertions, 38 deletions
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 <string.h> #include <atomic> // 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<DistanceAndTarget> 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 |