From d25f23805c6d7128b508a359d47af136dd2fd0db Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 11 Aug 2025 10:22:56 +0200 Subject: Wrapped pthread use in custom API --- src/utils/utils.h | 1 + src/utils/wrapthread.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/utils/wrapthread.h (limited to 'src/utils') diff --git a/src/utils/utils.h b/src/utils/utils.h index d14b285..b2ab64d 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -2,3 +2,4 @@ #include "constants.h" #include "math.h" #include "sleep.h" +#include "wrapthread.h" diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h new file mode 100644 index 0000000..482b67f --- /dev/null +++ b/src/utils/wrapthread.h @@ -0,0 +1,37 @@ +#if THREADS == 1 + +#define wrapthread_atomic + +#define wrapthread_define_var_thread_t(x) char x; (void)(x) +#define wrapthread_define_var_mutex_t(x) char x; (void)(x) +#define wrapthread_define_struct_thread_t(x) char x +#define wrapthread_define_struct_mutex_t(x) char x + +#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_mutex_lock(a) +#define wrapthread_mutex_unlock(a) + +#else + +#include + +#define wrapthread_atomic _Atomic + +#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_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_mutex_lock(a) pthread_mutex_lock(a) +#define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a) + +#endif -- cgit v1.3