diff options
| author | gingerBill <bill@gingerbill.org> | 2021-07-14 00:34:34 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-07-14 00:34:34 +0100 |
| commit | bd8e2f82bed231493718c811ea43e7aebed1fe8d (patch) | |
| tree | 544e78f168cb680ef9fb8cd804968789d6bf3884 /src/common.cpp | |
| parent | 69027b6840ae3e46291ff65353eb164ccb2f013e (diff) | |
Replace non-recursive mutexes with `BlockingMutex`; Minor improves to initialization improves
Diffstat (limited to 'src/common.cpp')
| -rw-r--r-- | src/common.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/common.cpp b/src/common.cpp index 70a049dc0..018afd803 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1299,3 +1299,41 @@ 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 |