diff options
| author | 2025-03-31 19:03:55 -0400 | |
|---|---|---|
| committer | 2025-03-31 19:03:55 -0400 | |
| commit | de6f6090f94b14ed98dac71956ff1bede48f1d8e (patch) | |
| tree | eac747f2c7620a8a360f88f83306856527ae2988 /tests | |
| parent | b4e45dd89e6dd53d8cb940e5609b812e19ade913 (diff) | |
| download | libnaunet-de6f6090f94b14ed98dac71956ff1bede48f1d8e.tar.gz libnaunet-de6f6090f94b14ed98dac71956ff1bede48f1d8e.tar.bz2 libnaunet-de6f6090f94b14ed98dac71956ff1bede48f1d8e.zip | |
Apply style changes, abide by strict aliasing
- Remove internal sending step in packet pool.
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/stdin_lines.c | 2 | ||||
| -rw-r--r-- | tests/timer_loop.c | 14 | ||||
| -rw-r--r-- | tests/timer_thread.c | 17 |
3 files changed, 19 insertions, 14 deletions
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 <nnwt/thread.h> #include <nnwt/timer.h> -#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 <nnwt/common.h> #include <nnwt/thread.h> -#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; } |