Rizin
unix-like reverse engineering framework and cli tools
thread.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2022 GustavoLCR <gugulcr@gmail.com>
2 // SPDX-FileCopyrightText: 2022 deroad <wargio@libero.it>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #ifndef RZ_THREAD_INTERNAL_H
6 #define RZ_THREAD_INTERNAL_H
7 #ifdef _GNU_SOURCE
8 #undef _GNU_SOURCE
9 #endif
10 #define _GNU_SOURCE
11 #include <rz_th.h>
12 #include <rz_types.h>
13 #include <rz_util/rz_assert.h>
14 
15 #if __WINDOWS__
16 #include <rz_windows.h>
17 #define RZ_TH_TID HANDLE
18 #define RZ_TH_LOCK_T CRITICAL_SECTION
19 #define RZ_TH_COND_T CONDITION_VARIABLE
20 #define RZ_TH_SEM_T HANDLE
21 #define RZ_TH_RET_T DWORD WINAPI
22 #elif HAVE_PTHREAD
23 #define __GNU
24 #include <semaphore.h>
25 #include <pthread.h>
26 #if __linux__
27 #include <sched.h>
28 #endif
29 #if __linux__ && __GLIBC_MINOR < 12
30 #define HAVE_PTHREAD_NP 0
31 #else
32 #define HAVE_PTHREAD_NP 1
33 #endif
34 #if __APPLE__
35 #include <pthread.h>
36 #endif
37 #if __FreeBSD__ || __OpenBSD__ || __DragonFly__
38 #if __FreeBSD__
39 #include <sys/cpuset.h>
40 #endif
41 #include <pthread_np.h>
42 #endif
43 #define RZ_TH_TID pthread_t
44 #define RZ_TH_LOCK_T pthread_mutex_t
45 #define RZ_TH_COND_T pthread_cond_t
46 #define RZ_TH_SEM_T sem_t *
47 #define RZ_TH_RET_T void *
48 #else
49 #error Threading library only supported for pthread and w32
50 #endif
51 
52 #if __APPLE__
53 // Here to avoid polluting mach types macro redefinitions...
54 #include <mach/thread_act.h>
55 #include <mach/thread_policy.h>
56 #endif
57 
58 #if __APPLE__ || __NetBSD__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __sun
59 #include <sys/param.h>
60 #include <sys/sysctl.h>
61 #endif
62 
63 #if __sun
64 #include <sys/pset.h>
65 #endif
66 
67 #if __HAIKU__
68 #include <kernel/scheduler.h>
69 #include <OS.h>
70 #endif
71 
72 struct rz_th_sem_t {
73  RZ_TH_SEM_T sem;
74 };
75 
76 struct rz_th_lock_t {
77  RZ_TH_LOCK_T lock;
78 };
79 
80 struct rz_th_cond_t {
81  RZ_TH_COND_T cond;
82 };
83 
84 struct rz_th_t {
85  RZ_TH_TID tid;
86  RzThreadFunction function;
87  void *user;
88  void *retv;
89 };
90 
91 RZ_IPI RZ_TH_TID rz_th_self(void);
92 
93 #endif /* RZ_THREAD_INTERNAL_H */
#define RZ_IPI
Definition: analysis_wasm.c:11
void *(* RzThreadFunction)(void *user)
Definition: rz_th.h:28
RZ_TH_COND_T cond
Definition: thread.h:81
RZ_TH_LOCK_T lock
Definition: thread.h:77
RZ_TH_SEM_T sem
Definition: thread.h:73
Definition: thread.h:84
void * retv
Thread return value.
Definition: thread.h:88
RZ_TH_TID tid
Thread identifier.
Definition: thread.h:85
void * user
User defined thread data to pass (can be NULL).
Definition: thread.h:87
RZ_IPI RZ_TH_TID rz_th_self(void)
Definition: thread.c:25