mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Improve spin lock for atomic_mutex_lock
This commit is contained in:
@@ -38,6 +38,9 @@ atomic_mutex_lock :: proc(m: ^Atomic_Mutex) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set just in case 100 iterations did not do it
|
||||||
|
new_state = .Waiting
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if atomic_exchange_acquire(&m.state, .Waiting) == .Unlocked {
|
if atomic_exchange_acquire(&m.state, .Waiting) == .Unlocked {
|
||||||
return
|
return
|
||||||
@@ -49,11 +52,7 @@ atomic_mutex_lock :: proc(m: ^Atomic_Mutex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch v := atomic_exchange_acquire(&m.state, .Locked); v {
|
if v := atomic_exchange_acquire(&m.state, .Locked); v != .Unlocked {
|
||||||
case .Unlocked:
|
|
||||||
// Okay
|
|
||||||
case: fallthrough
|
|
||||||
case .Locked, .Waiting:
|
|
||||||
lock_slow(m, v)
|
lock_slow(m, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user