Rename tryguard to try_guard (#34)

Co-authored-by: Zachary Levy <zachary@sunforge.is>
Reviewed-on: #34
This commit was merged in pull request #34.
This commit is contained in:
2026-06-06 02:58:20 +00:00
parent 962a814b84
commit 61d94265dd
+9 -9
View File
@@ -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
// 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
// }
@(deferred_in_out = spinlock_tryguard_unlock)
spinlock_tryguard :: #force_inline proc "contextless" (lock: ^Spinlock) -> bool {
@(deferred_in_out = spinlock_try_guard_unlock)
spinlock_try_guard :: #force_inline proc "contextless" (lock: ^Spinlock) -> bool {
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)
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 {
spinlock_unlock(lock)
}
@@ -178,8 +178,8 @@ guard :: proc {
spinlock_guard,
}
tryguard :: proc {
spinlock_tryguard,
try_guard :: proc {
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
// single lock and perform a deliberate non-atomic read-modify-write on shared
// 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.
//
// 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.
for {
if spinlock_tryguard(&s.lock) {
if spinlock_try_guard(&s.lock) {
critical_section(s)
break
}