ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

Commit: ba6fdc1589d2ee5762805d4cc426b58083ae7c96
Parent: 331f8407a09cf9b27f6103f95d3a7b3ddc9bc8dd
Author: Randy Palamar
Date:   Mon,  2 Nov 2026 04:56:42 -0800

util: spin_wait -> spin_while_true

the usage was sometimes not clear

Diffstat:
Mbeamformer.c | 4++--
Mbeamformer_core.c | 6+++---
Mutil.h | 3++-
3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/beamformer.c b/beamformer.c @@ -29,8 +29,8 @@ beamformer_debug_hot_release(void *memory, BeamformerInput *input) // TODO(rnp): this will deadlock if live imaging is active /* NOTE(rnp): spin until compute thread finishes its work (we will probably * never reload while compute is in progress but just incase). */ - spin_wait(atomic_load_u32(&ctx->upload_worker.awake)); - spin_wait(atomic_load_u32(&ctx->compute_worker.awake)); + spin_while_true(atomic_load_u32(&ctx->upload_worker.awake)); + spin_while_true(atomic_load_u32(&ctx->compute_worker.awake)); } BEAMFORMER_EXPORT void diff --git a/beamformer_core.c b/beamformer_core.c @@ -1461,7 +1461,7 @@ complete_queue(BeamformerCtx *ctx, BeamformWorkQueue *q, Arena *arena) case BeamformerExportKind_Stats:{ ComputeTimingTable *table = ctx->compute_timing_table; /* NOTE(rnp): do a little spin to let this finish updating */ - spin_wait(table->write_index != atomic_load_u32(&table->read_index)); + spin_while_true(table->write_index != atomic_load_u32(&table->read_index)); ComputeShaderStats *stats = ctx->compute_shader_stats; if (sizeof(stats->table) <= ec->size) memory_copy(beamformer_shared_memory_data_pointer(sm, ctx->shared_memory_size), @@ -1641,7 +1641,7 @@ complete_queue(BeamformerCtx *ctx, BeamformWorkQueue *q, Arena *arena) u32 wait_info_count = 0; GPUSemaphoreSignalInfo wait_info = {.semaphore = rf->upload_semaphore}; if (work->kind == BeamformerWorkKind_WaitThenCompute) { - spin_wait(atomic_load_u64(&rf->insertion_index) <= compute_index); + spin_while_true(atomic_load_u64(&rf->insertion_index) <= compute_index); wait_info.value = atomic_load_u64(rf->upload_complete_values + slot); wait_info_count = 1; } @@ -1810,7 +1810,7 @@ DEBUG_EXPORT BEAMFORMER_RF_UPLOAD_FN(beamformer_rf_upload) u64 slot = rf->insertion_index % countof(rf->upload_complete_values); /* NOTE(rnp): don't overwrite slot if the compute thread hasn't processed it */ - spin_wait(rf->insertion_index - atomic_load_u64(&rf->compute_index) >= countof(rf->upload_complete_values)); + spin_while_true(rf->insertion_index - atomic_load_u64(&rf->compute_index) >= countof(rf->upload_complete_values)); gpu_host_wait_timeline(GPUTimeline_Compute, rf->compute_complete_values[slot], -1ULL); assert((ctx->shared_memory_size % os_system_info()->page_size) == 0 && diff --git a/util.h b/util.h @@ -93,7 +93,8 @@ #define EachNonZeroEnumValue(type, it) (type it = (type)1; it < type##_Count; it = (type)(it + 1)) #define EachIndex(count, it) (u64 it = 0; it < count; it += 1) -#define spin_wait(c) while ((c)) cpu_yield() +#define spin_while_true(c) while ((c)) cpu_yield() +#define spin_while_false(c) while (!(c)) cpu_yield() // NOTE(rnp): typically for enums, wtf is wrong with modern compilers #define circular_add(v, add, max) (((u64)(v) + (u64)(max) + (i64)(add)) % (u64)(max))