summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-05-25 18:35:12 -0400
committerAndrew Opalach <andrew@akon.city> 2025-05-25 18:35:12 -0400
commit9fb3646511998310fc8c967c239803f38b2bdc5b (patch)
tree92f1bbc2c7cacfcf0c24b49f88ba220cdeebbde9 /tests
parentef86574ec5d859727695da65f683f0774a3b4460 (diff)
downloadlibnaunet-9fb3646511998310fc8c967c239803f38b2bdc5b.tar.gz
libnaunet-9fb3646511998310fc8c967c239803f38b2bdc5b.tar.bz2
libnaunet-9fb3646511998310fc8c967c239803f38b2bdc5b.zip
Windows XP support
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'tests')
-rw-r--r--tests/condition_variable.c39
-rw-r--r--tests/meson.build1
2 files changed, 40 insertions, 0 deletions
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 <al/lib.h>
+#include <nnwt/common.h>
+#include <nnwt/thread.h>
+
+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)