threading primitive bug fixes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 20 Oct 2021 18:19:03 +0000 (13:19 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 20 Oct 2021 18:19:03 +0000 (13:19 -0500)
core/sync/condition_variable.onyx
core/sync/semaphore.onyx

index b670c085bb6b4b1f5c079d97a5b8646ff92e8c01..8aa89274a24b8ce32546cfdb05d560080f71b466 100644 (file)
@@ -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) {
index 2a31af6d9e5a09baf52833d184ef1ed9dbe609f6..26f061e1168c16823f9b23d0085aef72253167c9 100644 (file)
@@ -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) {