From de6f6090f94b14ed98dac71956ff1bede48f1d8e Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 31 Mar 2025 19:03:55 -0400 Subject: Apply style changes, abide by strict aliasing - Remove internal sending step in packet pool. Signed-off-by: Andrew Opalach --- tests/stdin_lines.c | 2 +- tests/timer_loop.c | 14 ++++++++------ tests/timer_thread.c | 17 ++++++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/stdin_lines.c b/tests/stdin_lines.c index 258f3ce..e032a54 100644 --- a/tests/stdin_lines.c +++ b/tests/stdin_lines.c @@ -7,7 +7,7 @@ static struct nn_line_processor pro; static u8 line_callback(void *userdata, str *line) { (void)userdata; - al_printf("%.*s\n", al_str_fmt(line)); + al_printf("%.*s\n", al_str_x(line)); if (al_str_eq(line, &al_str_c("quit"))) return NNWT_LINE_PROCESSOR_STOP; return NNWT_LINE_PROCESSOR_CONTINUE; } diff --git a/tests/timer_loop.c b/tests/timer_loop.c index ece849e..5b9aab8 100644 --- a/tests/timer_loop.c +++ b/tests/timer_loop.c @@ -2,8 +2,8 @@ #include #include -#define DELAY 100000L -#define REPEAT 21u +#define DELAY 100000 +#define REPEAT 21 static struct nn_event_loop loop; static struct nn_timer timer; @@ -14,9 +14,11 @@ static u32 iter = 0u; static void timer_callback(void *userdata, struct nn_timer *timer) { (void)userdata; - u64 diff = (nn_get_tick() - start) * 1000000Lu; - nn_timer_set_repeat(timer, NNWT_TS_FROM_USEC(DELAY + ((s64)(iter * DELAY) - diff))); - al_printf("[%2u (%llu)] %lfs\n", iter, nn_get_timestamp(), diff / 1000000.0); + u64 now = nn_get_timestamp(); + u64 diff = (nn_get_tick() - start) * 1000000; + s64 adj = iter * DELAY - (s64)diff; + al_printf("[%2u (%llu)] %fs(%s%f)\n", iter, now, diff / 1000000.0, adj >= 0 ? "+" : "", adj / 1000000.0); + nn_timer_set_repeat(timer, NNWT_TS_FROM_USEC(MAX(DELAY + adj, (s64)1))); if (++iter == REPEAT) nn_timer_stop(timer); else nn_timer_again(timer); } @@ -27,9 +29,9 @@ s32 main(void) nn_event_loop_init(&loop); + start = nn_get_tick(); nn_timer_init(&timer, &loop, timer_callback, NULL); nn_timer_set_repeat(&timer, NNWT_TS_FROM_USEC(DELAY)); - start = nn_get_tick(); timer_callback(NULL, &timer); nn_event_loop_run(&loop); diff --git a/tests/timer_thread.c b/tests/timer_thread.c index f6627dc..3f68ae4 100644 --- a/tests/timer_thread.c +++ b/tests/timer_thread.c @@ -1,20 +1,23 @@ #include #include -#define DELAY 100000L -#define REPEAT 21u +#define DELAY 100000 +#define REPEAT 21 static struct nn_thread thread; static nn_thread_result NNWT_THREADCALL test_thread(void *userdata) { (void)userdata; - u64 diff; + u64 now, diff; + s64 adj; f64 start = nn_get_tick(); - for (u32 i = 0; i < REPEAT; i++) { - diff = (nn_get_tick() - start) * 1000000Lu; - nn_thread_sleep(NNWT_TS_FROM_USEC(DELAY + ((s64)(i * DELAY) - diff))); - al_printf("[%2u (%llu)] %lfs\n", i, nn_get_timestamp(), diff / 1000000.0); + for (u32 iter = 0; iter < REPEAT; iter++) { + now = nn_get_timestamp(); + diff = (nn_get_tick() - start) * 1000000; + adj = iter * DELAY - (s64)diff; + al_printf("[%2u (%llu)] %fs(%s%f)\n", iter, now, diff / 1000000.0, adj >= 0 ? "+" : "", adj / 1000000.0); + nn_thread_sleep(NNWT_TS_FROM_USEC(MAX(DELAY + adj, (s64)1))); } return 0; } -- cgit v1.2.3-101-g0448