Browse Source

Remove `prev` from `Atomic_Cond`

gingerBill 3 years ago
parent
commit
d6cfb60506
1 changed files with 3 additions and 7 deletions
  1. 3 7
      core/sync/primitives_atomic.odin

+ 3 - 7
core/sync/primitives_atomic.odin

@@ -287,12 +287,10 @@ atomic_recursive_mutex_guard :: proc(m: ^Atomic_Recursive_Mutex) -> bool {
 // An Atomic_Cond must not be copied after first use
 Atomic_Cond :: struct {
 	state: Futex,
-	prev:  u32,
 }
 
 atomic_cond_wait :: proc(c: ^Atomic_Cond, m: ^Atomic_Mutex) {
-	state := u32(atomic_load(&c.state))
-	atomic_store(&c.prev, state)
+	state := u32(atomic_load_explicit(&c.state, .Relaxed))
 	unlock(m)
 	futex_wait(&c.state, state)
 	lock(m)
@@ -309,14 +307,12 @@ atomic_cond_wait_with_timeout :: proc(c: ^Atomic_Cond, m: ^Atomic_Mutex, duratio
 
 
 atomic_cond_signal :: proc(c: ^Atomic_Cond) {
-	state := 1 + atomic_load(&c.prev)
-	atomic_store(&c.state, Futex(state))
+	atomic_add_explicit(&c.state, 1, .Relaxed)
 	futex_signal(&c.state)
 }
 
 atomic_cond_broadcast :: proc(c: ^Atomic_Cond) {
-	state := 1 + atomic_load(&c.prev)
-	atomic_store(&c.state, Futex(state))
+	atomic_add_explicit(&c.state, 1, .Relaxed)
 	futex_broadcast(&c.state)
 }