diff options
| author | gingerBill <bill@gingerbill.org> | 2024-02-13 16:54:41 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-02-13 16:54:41 +0000 |
| commit | d496dbf3a0ee05819ab6e802939b4219cfa9c7fe (patch) | |
| tree | db58abf52b3f3f20cb970b66dc24eaaf578dae66 /src/threading.cpp | |
| parent | cbfb32c34c09fd13098f0127bc98c88b53587a97 (diff) | |
Fix race condition with #soa
Diffstat (limited to 'src/threading.cpp')
| -rw-r--r-- | src/threading.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/threading.cpp b/src/threading.cpp index b8bc9b118..731394126 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -107,6 +107,22 @@ gb_internal void thread_set_name (Thread *t, char const *name); gb_internal void yield_thread(void); gb_internal void yield_process(void); +struct Wait_Signal { + Futex futex; +}; + +gb_internal void wait_signal_until_available(Wait_Signal *ws) { + if (ws->futex.load() == 0) { + futex_wait(&ws->futex, 1); + } +} + +gb_internal void wait_signal_set(Wait_Signal *ws) { + ws->futex.store(1); + futex_broadcast(&ws->futex); +} + + struct MutexGuard { MutexGuard() = delete; |