From e68606ff95db6e31585706278b034250555bbe14 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 1 Mar 2026 16:26:58 +0000 Subject: C11 threads? --- src/utils/wrapthread.h | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/utils') diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h index 28654fe..d5de155 100644 --- a/src/utils/wrapthread.h +++ b/src/utils/wrapthread.h @@ -9,13 +9,32 @@ #define wrapthread_define_if_threads(T, x) T x; (void)(x) -#define wrapthread_create(a, b, c, d) c(d) -#define wrapthread_join(a, b) -#define wrapthread_mutex_init(a, b) +#define wrapthread_create(t, f, arg) f(arg) +#define wrapthread_join(a) +#define wrapthread_mutex_init(a) #define wrapthread_mutex_lock(a) #define wrapthread_mutex_unlock(a) -#else +#elif defined(_WIN32) + +#include + +#define wrapthread_atomic _Atomic + +#define wrapthread_define_var_thread_t(x) thrd_t x +#define wrapthread_define_var_mutex_t(x) mtx_t x +#define wrapthread_define_struct_thread_t(x) thrd_t x +#define wrapthread_define_struct_mutex_t(x) mtx_t x + +#define wrapthread_define_if_threads(T, x) T x + +#define wrapthread_create(a, f, arg) thrd_create(a, (int(*)(void *))f, arg) +#define wrapthread_join(a) thrd_join(a, NULL) +#define wrapthread_mutex_init(a) mtx_init(a, mtx_plain) +#define wrapthread_mutex_lock(a) mtx_lock(a) +#define wrapthread_mutex_unlock(a) mtx_unlock(a) + +#elif defined(__unix__) #include @@ -28,9 +47,9 @@ #define wrapthread_define_if_threads(T, x) T x -#define wrapthread_create(a, b, c, d) pthread_create(a, b, c, d) -#define wrapthread_join(a, b) pthread_join(a, b) -#define wrapthread_mutex_init(a, b) pthread_mutex_init(a, b) +#define wrapthread_create(a, f, arg) pthread_create(a, NULL, f, arg) +#define wrapthread_join(a) pthread_join(a, NULL) +#define wrapthread_mutex_init(a) pthread_mutex_init(a, NULL) #define wrapthread_mutex_lock(a) pthread_mutex_lock(a) #define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a) -- cgit v1.3