From 9fb3646511998310fc8c967c239803f38b2bdc5b Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sun, 25 May 2025 18:35:12 -0400 Subject: Windows XP support Signed-off-by: Andrew Opalach --- tests/condition_variable.c | 39 +++++++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 2 files changed, 40 insertions(+) create mode 100644 tests/condition_variable.c (limited to 'tests') diff --git a/tests/condition_variable.c b/tests/condition_variable.c new file mode 100644 index 0000000..6bc5435 --- /dev/null +++ b/tests/condition_variable.c @@ -0,0 +1,39 @@ +#include +#include +#include + +static struct nn_mutex mutex; +static struct nn_cond cond; +static struct nn_thread thread; + +static nn_thread_result NNWT_THREADCALL test_thread(void *userdata) +{ + (void)userdata; + + nn_mutex_lock(&mutex); + nn_cond_wait(&cond, &mutex); + nn_mutex_unlock(&mutex); + + return 0; +} + +s32 main(void) +{ + if (!nn_common_init()) return EXIT_FAILURE; + + nn_mutex_init(&mutex); + nn_cond_init(&cond); + + nn_thread_create(&thread, test_thread, NULL); + + nn_thread_sleep(NNWT_TS_FROM_USEC(1000000)); + + nn_mutex_lock(&mutex); + nn_cond_signal(&cond); + // cond_wait() won't return until we unlock here. + nn_mutex_unlock(&mutex); + + nn_thread_join(&thread); + + return EXIT_SUCCESS; +} diff --git a/tests/meson.build b/tests/meson.build index 38b2af8..0482bec 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -2,6 +2,7 @@ executable('timer_thread', ['timer_thread.c'], dependencies: naunet) executable('timer_loop', ['timer_loop.c'], dependencies: naunet) executable('loop_sleep', ['loop_sleep.c'], dependencies: naunet) executable('misc_file', ['misc_file.c'], dependencies: naunet) +executable('condition_variable', ['condition_variable.c'], dependencies: naunet) if not is_windows executable('stdin_lines', ['stdin_lines.c'], dependencies: naunet) executable('fs_event', ['fs_event_local.c'], dependencies: naunet) -- cgit v1.2.3-101-g0448