From a676d598ff6286bdb64b2803dee515c1436aa3bb Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 1 Mar 2026 17:25:05 +0100 Subject: Better macros --- src/utils/wrapthread.h | 83 +++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) (limited to 'src/utils') diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h index 843a37d..e14a473 100644 --- a/src/utils/wrapthread.h +++ b/src/utils/wrapthread.h @@ -1,61 +1,62 @@ #if THREADS == 1 -#define WRAPTHREADS_NOTHREADS 1 + #define WRAPTHREADS_NOTHREADS 1 +#elif defined(__unix__) + #define WRAPTHREADS_PTHREADS 1 +#elif !defined(__STDC_NO_THREADS__) + #define WRAPTHREADS_C11THREADS 1 +#elif defined(__has_include) + #if __has_include() + #define WRAPTHREADS_PTHREADS 1 + #elif __has_include() + #define WRAPTHREADS_C11THREADS 1 + #endif #endif -#if !WRAPTHREADS_NOTHREADS - - #if defined(__unix__) - - #include - - #define wrapthread_atomic _Atomic +#if WRAPTHREADS_PTHREADS - #define wrapthread_return_t int - #define wrapthread_return_val 0 + #include - #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_atomic _Atomic - #define wrapthread_define_if_threads(T, x) T x + #define wrapthread_return_t void * + #define wrapthread_return_val NULL - #define wrapthread_create(a, f, arg) thrd_create(a, 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) + #define wrapthread_define_var_thread_t(x) pthread_t x + #define wrapthread_define_var_mutex_t(x) pthread_mutex_t x + #define wrapthread_define_struct_thread_t(x) pthread_t x + #define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x - #elif !defined(__STDC_NO_THREADS__) + #define wrapthread_define_if_threads(T, x) T x - #include + #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) - #define wrapthread_atomic _Atomic +#elif WRAPTHREADS_C11THREADS - #define wrapthread_return_t void * - #define wrapthread_return_val NULL + #include - #define wrapthread_define_var_thread_t(x) pthread_t x - #define wrapthread_define_var_mutex_t(x) pthread_mutex_t x - #define wrapthread_define_struct_thread_t(x) pthread_t x - #define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x + #define wrapthread_atomic _Atomic - #define wrapthread_define_if_threads(T, x) T x + #define wrapthread_return_t int + #define wrapthread_return_val 0 - #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) + #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 - #else - #define WRAPTHREADS_NOTHREADS 1 - #endif + #define wrapthread_define_if_threads(T, x) T x -#endif + #define wrapthread_create(a, f, arg) thrd_create(a, 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) -#if WRAPTHREADS_NOTHREADS +#else #define wrapthread_atomic -- cgit v1.3