diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-09-08 15:27:28 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-09-09 16:19:14 -0400 |
| commit | 9d6f71fd2ed0a290781e547c7573e86010ff660f (patch) | |
| tree | 2dbf5114f14d0545a53804e70d91a3ea04e0b8e4 /core | |
| parent | d783bca2979db5955885ee6b2a06f20f8a847582 (diff) | |
Fix `sync.Benaphore`
The calls to `atomic_add*` return the value before adding, not after, so
the previous code was causing the occasional data race.
Diffstat (limited to 'core')
| -rw-r--r-- | core/sync/extended.odin | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/core/sync/extended.odin b/core/sync/extended.odin index b446fefa0..ffba40ef8 100644 --- a/core/sync/extended.odin +++ b/core/sync/extended.odin @@ -355,7 +355,7 @@ from entering any critical sections associated with the same benaphore, until until the lock is released. */ benaphore_lock :: proc "contextless" (b: ^Benaphore) { - if atomic_add_explicit(&b.counter, 1, .Acquire) > 1 { + if atomic_add_explicit(&b.counter, 1, .Acquire) > 0 { sema_wait(&b.sema) } } @@ -384,7 +384,7 @@ are waiting on the lock, exactly one thread is allowed into a critical section associated with the same banaphore. */ benaphore_unlock :: proc "contextless" (b: ^Benaphore) { - if atomic_sub_explicit(&b.counter, 1, .Release) > 0 { + if atomic_sub_explicit(&b.counter, 1, .Release) > 1 { sema_post(&b.sema) } } @@ -740,4 +740,4 @@ Make event available. one_shot_event_signal :: proc "contextless" (e: ^One_Shot_Event) { atomic_store_explicit(&e.state, 1, .Release) futex_broadcast(&e.state) -}
\ No newline at end of file +} |