Commit: a515e3b36273853875e45f9f0b0f8562c70a0182
Parent: 7aadc25e0c62338a7f934499d7869c4c1f425590
Author: Randy Palamar
Date: Mon, 17 Nov 2025 12:48:11 -0700
os: os_take_lock: fix return behaviour for infinite timeouts
callers of this function expect that it will not return until the
lock is successfully acquired. this means that regardless of what
the underlying syscall returns it is never an error for an
infinite timeout.
I noticed this when the value would change between the atomic_cas
and entering the kernel.
Diffstat:
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -1414,9 +1414,10 @@ DEBUG_EXPORT BEAMFORMER_RF_UPLOAD_FN(beamformer_rf_upload)
u64 rf_block_rf_size;
if (atomic_load_u32(sm->locks + upload_lock) &&
- (rf_block_rf_size = atomic_swap_u64(&sm->rf_block_rf_size, 0)) &&
- os_shared_memory_region_lock(ctx->shared_memory, sm->locks, (i32)scratch_lock, (u32)-1))
+ (rf_block_rf_size = atomic_swap_u64(&sm->rf_block_rf_size, 0)))
{
+ os_shared_memory_region_lock(ctx->shared_memory, sm->locks, (i32)scratch_lock, (u32)-1);
+
BeamformerRFBuffer *rf = ctx->rf_buffer;
BeamformerParameterBlock *b = beamformer_parameter_block(sm, (u32)(rf_block_rf_size >> 32ULL));
BeamformerParameters *bp = &b->parameters;
diff --git a/os_linux.c b/os_linux.c
@@ -290,7 +290,7 @@ os_take_lock(i32 *lock, i32 timeout_ms)
i32 current = 0;
if (atomic_cas_u32(lock, ¤t, 1))
result = 1;
- if (result || !timeout_ms || !os_wait_on_value(lock, current, (u32)timeout_ms))
+ if (result || !timeout_ms || (!os_wait_on_value(lock, current, (u32)timeout_ms) && timeout_ms != -1))
break;
}
return result;
diff --git a/os_win32.c b/os_win32.c
@@ -431,7 +431,7 @@ os_take_lock(i32 *lock, i32 timeout_ms)
i32 current = 0;
if (atomic_cas_u32(lock, ¤t, 1))
result = 1;
- if (result || !timeout_ms || !os_wait_on_value(lock, current, (u32)timeout_ms))
+ if (result || !timeout_ms || (!os_wait_on_value(lock, current, (u32)timeout_ms) && timeout_ms != -1))
break;
}
return result;