aboutsummaryrefslogtreecommitdiff
path: root/src/utils/wrapthread.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-03-01 18:09:44 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2026-03-01 18:09:44 +0100
commit2c291aed4bb80f07e8557284d3399cf1e2a4ccb9 (patch)
tree2c009a3ad206842b07b1cd758b8192e2154231e9 /src/utils/wrapthread.h
parentdff3a040637f2985b5b5e369148a993183964096 (diff)
downloadnissy-core-2c291aed4bb80f07e8557284d3399cf1e2a4ccb9.tar.gz
nissy-core-2c291aed4bb80f07e8557284d3399cf1e2a4ccb9.zip
Improve Windows build support.
- Use multithreading (works with a sufficiently recent version of the Microsoft developer tools / C SDK). - Detect CPU architecture and use AVX2 or NEON when appropriate. - Automatically detect python installation path.
Diffstat (limited to '')
-rw-r--r--src/utils/wrapthread.h86
1 files changed, 63 insertions, 23 deletions
diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h
index 28654fe..4ac72a6 100644
--- a/src/utils/wrapthread.h
+++ b/src/utils/wrapthread.h
@@ -1,37 +1,77 @@
1#if THREADS == 1 1#if THREADS == 1
2 #define WRAPTHREAD_NOTHREADS 1
3#elif defined(__unix__)
4 #define WRAPTHREAD_PTHREADS 1
5#elif defined(__has_include)
6 #if __has_include(<pthreads.h>)
7 #define WRAPTHREAD_PTHREADS 1
8 #elif __has_include(<threads.h>)
9 #define WRAPTHREAD_C11THREADS 1
10 #endif
11#else
12 #define WRAPTHREAD_NOTHREADS 1
13#endif
14
15#if WRAPTHREAD_PTHREADS
16 #include <pthread.h>
17
18 #define wrapthread_atomic _Atomic
19
20 #define wrapthread_return_t void *
21 #define wrapthread_return_val NULL
22
23 #define wrapthread_define_var_thread_t(x) pthread_t x
24 #define wrapthread_define_var_mutex_t(x) pthread_mutex_t x
25 #define wrapthread_define_struct_thread_t(x) pthread_t x
26 #define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x
27
28 #define wrapthread_define_if_threads(T, x) T x
29
30 #define wrapthread_create(a, f, arg) pthread_create(a, NULL, f, arg)
31 #define wrapthread_join(a) pthread_join(a, NULL)
32 #define wrapthread_mutex_init(a) pthread_mutex_init(a, NULL)
33 #define wrapthread_mutex_lock(a) pthread_mutex_lock(a)
34 #define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a)
35
36#elif WRAPTHREAD_C11THREADS
37 #include <threads.h>
38
39 #define wrapthread_atomic _Atomic
2 40
3#define wrapthread_atomic 41 #define wrapthread_return_t int
42 #define wrapthread_return_val 0
4 43
5#define wrapthread_define_var_thread_t(x) unused char x 44 #define wrapthread_define_var_thread_t(x) thrd_t x
6#define wrapthread_define_var_mutex_t(x) unused char x 45 #define wrapthread_define_var_mutex_t(x) mtx_t x
7#define wrapthread_define_struct_thread_t(x) char x 46 #define wrapthread_define_struct_thread_t(x) thrd_t x
8#define wrapthread_define_struct_mutex_t(x) char x 47 #define wrapthread_define_struct_mutex_t(x) mtx_t x
9 48
10#define wrapthread_define_if_threads(T, x) T x; (void)(x) 49 #define wrapthread_define_if_threads(T, x) T x
11 50
12#define wrapthread_create(a, b, c, d) c(d) 51 #define wrapthread_create(a, f, arg) thrd_create(a, f, arg)
13#define wrapthread_join(a, b) 52 #define wrapthread_join(a) thrd_join(a, NULL)
14#define wrapthread_mutex_init(a, b) 53 #define wrapthread_mutex_init(a) mtx_init(a, mtx_plain)
15#define wrapthread_mutex_lock(a) 54 #define wrapthread_mutex_lock(a) mtx_lock(a)
16#define wrapthread_mutex_unlock(a) 55 #define wrapthread_mutex_unlock(a) mtx_unlock(a)
17 56
18#else 57#else
19 58
20#include <pthread.h> 59 #define wrapthread_atomic
21 60
22#define wrapthread_atomic _Atomic 61 #define wrapthread_return_t int
62 #define wrapthread_return_val 0
23 63
24#define wrapthread_define_var_thread_t(x) pthread_t x 64 #define wrapthread_define_var_thread_t(x) unused char x
25#define wrapthread_define_var_mutex_t(x) pthread_mutex_t x 65 #define wrapthread_define_var_mutex_t(x) unused char x
26#define wrapthread_define_struct_thread_t(x) pthread_t x 66 #define wrapthread_define_struct_thread_t(x) char x
27#define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x 67 #define wrapthread_define_struct_mutex_t(x) char x
28 68
29#define wrapthread_define_if_threads(T, x) T x 69 #define wrapthread_define_if_threads(T, x) T x; (void)(x)
30 70
31#define wrapthread_create(a, b, c, d) pthread_create(a, b, c, d) 71 #define wrapthread_create(t, f, arg) f(arg)
32#define wrapthread_join(a, b) pthread_join(a, b) 72 #define wrapthread_join(a)
33#define wrapthread_mutex_init(a, b) pthread_mutex_init(a, b) 73 #define wrapthread_mutex_init(a)
34#define wrapthread_mutex_lock(a) pthread_mutex_lock(a) 74 #define wrapthread_mutex_lock(a)
35#define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a) 75 #define wrapthread_mutex_unlock(a)
36 76
37#endif 77#endif

Generated with cgit - Back to sebastiano.tronto.net