Commit: ca621f7d047fa723b32e6a172785f837d65fc734
Parent: 35d37d9b3f6e247152f07487d579dcf701c86d68
Author: Randy Palamar
Date: Wed, 18 Jun 2025 08:47:52 -0600
tests/throughput: properly exit on SIGINT
this prevents a lock from becoming stuck when we exit in the
middle of a mem_copy. according to w32 docs this works there as well
Diffstat:
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/tests/throughput.c b/tests/throughput.c
@@ -6,6 +6,7 @@
#include "ogl_beamformer_lib.c"
+#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -47,6 +48,8 @@ typedef struct {
u32 transmit_mode;
} zemp_bp_v1;
+global b32 g_should_exit;
+
#define die(...) die_((char *)__func__, __VA_ARGS__)
function no_return void
die_(char *function_name, char *format, ...)
@@ -381,7 +384,7 @@ execute_study(s8 study, Arena arena, Stream path, Options *options)
f32 times[32] = {0};
f32 data_size = bp.rf_raw_dim[0] * bp.rf_raw_dim[1] * sizeof(*data);
f64 start = os_get_time();
- for (;;) {
+ for (;!g_should_exit;) {
if (send_frame(data, &bp)) {
f64 now = os_get_time();
f32 delta = now - start;
@@ -406,7 +409,13 @@ execute_study(s8 study, Arena arena, Stream path, Options *options)
free(data);
}
-int
+function void
+sigint(i32 _signo)
+{
+ g_should_exit = 1;
+}
+
+extern i32
main(i32 argc, char *argv[])
{
Options options = parse_argv(argc, argv);
@@ -416,6 +425,8 @@ main(i32 argc, char *argv[])
os_init_timer();
+ signal(SIGINT, sigint);
+
Arena arena = os_alloc_arena((Arena){0}, KB(8));
Stream path = stream_alloc(&arena, KB(4));
stream_append_s8(&path, c_str_to_s8(options.remaining[0]));