From: Brendan Hansen Date: Wed, 20 Oct 2021 18:19:03 +0000 (-0500) Subject: threading primitive bug fixes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=9d626daaaaf49240fb02b76d29beb0fc9cdfdd59;p=onyx.git threading primitive bug fixes --- diff --git a/core/sync/condition_variable.onyx b/core/sync/condition_variable.onyx index b670c085..8aa89274 100644 --- a/core/sync/condition_variable.onyx +++ b/core/sync/condition_variable.onyx @@ -32,9 +32,9 @@ condition_wait :: (c: ^Condition_Variable, m: ^Mutex) { semaphore_init(^node.semaphore, 0); mutex_unlock(^c.mutex); - mutex_unlock(m); + if m != null do mutex_unlock(m); semaphore_wait(^node.semaphore); - mutex_lock(m); + if m != null do mutex_lock(m); } condition_signal :: (c: ^Condition_Variable) { diff --git a/core/sync/semaphore.onyx b/core/sync/semaphore.onyx index 2a31af6d..26f061e1 100644 --- a/core/sync/semaphore.onyx +++ b/core/sync/semaphore.onyx @@ -18,9 +18,11 @@ semaphore_destroy :: (s: ^Semaphore) { } semaphore_post :: (s: ^Semaphore, count := 1) { + if count == 0 do return; + scoped_mutex(^s.mutex); s.counter += count; - __atomic_notify(^s.counter, maximum = 1); + __atomic_notify(^s.counter, maximum = count); } semaphore_wait :: (s: ^Semaphore) {