Rename tryguard to try_guard
This commit is contained in:
@@ -146,17 +146,17 @@ spinlock_guard :: #force_inline proc "contextless" (lock: ^Spinlock) -> bool {
|
|||||||
// Tries to acquire the lock once without spinning. Returns true and unlocks at the end of the
|
// Tries to acquire the lock once without spinning. Returns true and unlocks at the end of the
|
||||||
// calling scope if acquired, otherwise returns false and does nothing:
|
// calling scope if acquired, otherwise returns false and does nothing:
|
||||||
//
|
//
|
||||||
// if spinlock_tryguard(&lock) {
|
// if spinlock_try_guard(&lock) {
|
||||||
// // critical section, entered only if the lock was acquired
|
// // critical section, entered only if the lock was acquired
|
||||||
// }
|
// }
|
||||||
@(deferred_in_out = spinlock_tryguard_unlock)
|
@(deferred_in_out = spinlock_try_guard_unlock)
|
||||||
spinlock_tryguard :: #force_inline proc "contextless" (lock: ^Spinlock) -> bool {
|
spinlock_try_guard :: #force_inline proc "contextless" (lock: ^Spinlock) -> bool {
|
||||||
return spinlock_try_lock(lock)
|
return spinlock_try_lock(lock)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deferred companion of `spinlock_tryguard`; unlocks only when the lock was actually acquired.
|
// Deferred companion of `spinlock_try_guard`; unlocks only when the lock was actually acquired.
|
||||||
@(private)
|
@(private)
|
||||||
spinlock_tryguard_unlock :: #force_inline proc "contextless" (lock: ^Spinlock, locked: bool) {
|
spinlock_try_guard_unlock :: #force_inline proc "contextless" (lock: ^Spinlock, locked: bool) {
|
||||||
if locked {
|
if locked {
|
||||||
spinlock_unlock(lock)
|
spinlock_unlock(lock)
|
||||||
}
|
}
|
||||||
@@ -178,8 +178,8 @@ guard :: proc {
|
|||||||
spinlock_guard,
|
spinlock_guard,
|
||||||
}
|
}
|
||||||
|
|
||||||
tryguard :: proc {
|
try_guard :: proc {
|
||||||
spinlock_tryguard,
|
spinlock_try_guard,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -479,7 +479,7 @@ test_atomic_release_acquire_publish_visibility :: proc(t: ^testing.T) {
|
|||||||
// Stress test for every spinlock acquisition variant: N threads contend on a
|
// Stress test for every spinlock acquisition variant: N threads contend on a
|
||||||
// single lock and perform a deliberate non-atomic read-modify-write on shared
|
// single lock and perform a deliberate non-atomic read-modify-write on shared
|
||||||
// data. Each iteration rotates through spinlock_try_lock, spinlock_lock,
|
// data. Each iteration rotates through spinlock_try_lock, spinlock_lock,
|
||||||
// spinlock_guard, and spinlock_tryguard so every variant runs concurrently and
|
// spinlock_guard, and spinlock_try_guard so every variant runs concurrently and
|
||||||
// must uphold mutual exclusion on the same lock.
|
// must uphold mutual exclusion on the same lock.
|
||||||
//
|
//
|
||||||
// If mutual exclusion holds:
|
// If mutual exclusion holds:
|
||||||
@@ -566,7 +566,7 @@ test_spinlock_mutual_exclusion :: proc(t: ^testing.T) {
|
|||||||
}
|
}
|
||||||
case 3: // Scoped try-guard: retry until acquired, auto-unlocks on success.
|
case 3: // Scoped try-guard: retry until acquired, auto-unlocks on success.
|
||||||
for {
|
for {
|
||||||
if spinlock_tryguard(&s.lock) {
|
if spinlock_try_guard(&s.lock) {
|
||||||
critical_section(s)
|
critical_section(s)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user