libc/new/common/posix/
pthread.rs

1//! Header: `pthread.h`
2//!
3//! <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html>
4
5use crate::prelude::*;
6
7extern "C" {
8    #[cfg(any(target_os = "android", target_os = "linux"))]
9    pub fn pthread_atfork(
10        prepare: Option<unsafe extern "C" fn()>,
11        parent: Option<unsafe extern "C" fn()>,
12        child: Option<unsafe extern "C" fn()>,
13    ) -> c_int;
14
15    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
16    pub fn pthread_attr_getguardsize(
17        attr: *const crate::pthread_attr_t,
18        guardsize: *mut size_t,
19    ) -> c_int;
20
21    #[cfg(any(
22        target_os = "android",
23        target_os = "l4re",
24        target_os = "linux",
25        target_vendor = "apple",
26    ))]
27    pub fn pthread_attr_getinheritsched(
28        attr: *const crate::pthread_attr_t,
29        inheritsched: *mut c_int,
30    ) -> c_int;
31
32    #[cfg(any(target_os = "l4re", target_os = "linux", target_vendor = "apple"))]
33    pub fn pthread_attr_getschedparam(
34        attr: *const crate::pthread_attr_t,
35        param: *mut crate::sched_param,
36    ) -> c_int;
37
38    #[cfg(any(target_os = "l4re", target_os = "linux", target_vendor = "apple"))]
39    pub fn pthread_attr_getschedpolicy(
40        attr: *const crate::pthread_attr_t,
41        policy: *mut c_int,
42    ) -> c_int;
43
44    #[cfg(any(
45        target_os = "android",
46        target_os = "emscripten",
47        target_os = "linux",
48        target_os = "l4re"
49    ))]
50    pub fn pthread_attr_getstack(
51        attr: *const crate::pthread_attr_t,
52        stackaddr: *mut *mut c_void,
53        stacksize: *mut size_t,
54    ) -> c_int;
55
56    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
57    pub fn pthread_attr_setguardsize(attr: *mut crate::pthread_attr_t, guardsize: size_t) -> c_int;
58
59    #[cfg(any(
60        target_os = "android",
61        target_os = "l4re",
62        target_os = "linux",
63        target_vendor = "apple"
64    ))]
65    pub fn pthread_attr_setinheritsched(
66        attr: *mut crate::pthread_attr_t,
67        inheritsched: c_int,
68    ) -> c_int;
69
70    #[cfg(any(target_os = "l4re", target_os = "linux", target_vendor = "apple"))]
71    pub fn pthread_attr_setschedparam(
72        attr: *mut crate::pthread_attr_t,
73        param: *const crate::sched_param,
74    ) -> c_int;
75
76    #[cfg(any(target_os = "l4re", target_os = "linux", target_vendor = "apple"))]
77    pub fn pthread_attr_setschedpolicy(attr: *mut crate::pthread_attr_t, policy: c_int) -> c_int;
78
79    #[cfg(any(
80        target_os = "android",
81        target_os = "emscripten",
82        target_os = "linux",
83        target_os = "l4re"
84    ))]
85    pub fn pthread_attr_setstack(
86        attr: *mut crate::pthread_attr_t,
87        stackaddr: *mut c_void,
88        stacksize: size_t,
89    ) -> c_int;
90
91    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
92    pub fn pthread_barrier_destroy(barrier: *mut crate::pthread_barrier_t) -> c_int;
93
94    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
95    pub fn pthread_barrier_init(
96        barrier: *mut crate::pthread_barrier_t,
97        attr: *const crate::pthread_barrierattr_t,
98        count: c_uint,
99    ) -> c_int;
100
101    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
102    pub fn pthread_barrier_wait(barrier: *mut crate::pthread_barrier_t) -> c_int;
103
104    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
105    pub fn pthread_barrierattr_destroy(attr: *mut crate::pthread_barrierattr_t) -> c_int;
106
107    #[cfg(any(target_os = "android", target_os = "linux"))]
108    pub fn pthread_barrierattr_getpshared(
109        attr: *const crate::pthread_barrierattr_t,
110        shared: *mut c_int,
111    ) -> c_int;
112
113    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
114    pub fn pthread_barrierattr_init(attr: *mut crate::pthread_barrierattr_t) -> c_int;
115
116    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
117    pub fn pthread_barrierattr_setpshared(
118        attr: *mut crate::pthread_barrierattr_t,
119        shared: c_int,
120    ) -> c_int;
121
122    #[cfg(any(target_os = "l4re", all(target_os = "linux", not(target_env = "ohos"))))]
123    pub fn pthread_cancel(thread: crate::pthread_t) -> c_int;
124
125    #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux",))]
126    pub fn pthread_condattr_getclock(
127        attr: *const crate::pthread_condattr_t,
128        clock_id: *mut crate::clockid_t,
129    ) -> c_int;
130
131    #[cfg(any(
132        target_os = "android",
133        target_os = "l4re",
134        target_os = "linux",
135        target_vendor = "apple",
136    ))]
137    pub fn pthread_condattr_getpshared(
138        attr: *const crate::pthread_condattr_t,
139        pshared: *mut c_int,
140    ) -> c_int;
141
142    #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux",))]
143    pub fn pthread_condattr_setclock(
144        attr: *mut crate::pthread_condattr_t,
145        clock_id: crate::clockid_t,
146    ) -> c_int;
147
148    #[cfg(any(
149        target_os = "android",
150        target_os = "emscripten",
151        target_os = "linux",
152        target_os = "l4re",
153        target_vendor = "apple",
154    ))]
155    pub fn pthread_condattr_setpshared(
156        attr: *mut crate::pthread_condattr_t,
157        pshared: c_int,
158    ) -> c_int;
159
160    #[cfg(any(
161        target_os = "android",
162        target_os = "emscripten",
163        target_os = "l4re",
164        target_os = "linux",
165    ))]
166    pub fn pthread_create(
167        native: *mut crate::pthread_t,
168        attr: *const crate::pthread_attr_t,
169        f: extern "C" fn(*mut c_void) -> *mut c_void,
170        value: *mut c_void,
171    ) -> c_int;
172
173    #[cfg(any(target_os = "android", target_os = "linux"))]
174    pub fn pthread_getcpuclockid(thread: crate::pthread_t, clk_id: *mut crate::clockid_t) -> c_int;
175
176    #[cfg(any(
177        target_os = "android",
178        target_os = "l4re",
179        target_os = "linux",
180        target_vendor = "apple",
181    ))]
182    pub fn pthread_getschedparam(
183        native: crate::pthread_t,
184        policy: *mut c_int,
185        param: *mut crate::sched_param,
186    ) -> c_int;
187
188    // FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
189    // in pthread.
190    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
191    pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
192
193    #[cfg(all(target_os = "linux", not(target_env = "ohos")))]
194    pub fn pthread_mutex_consistent(mutex: *mut crate::pthread_mutex_t) -> c_int;
195
196    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
197    #[cfg_attr(gnu_time_bits64, link_name = "__pthread_mutex_timedlock64")]
198    #[cfg_attr(musl32_time64, link_name = "__pthread_mutex_timedlock_time64")]
199    pub fn pthread_mutex_timedlock(
200        lock: *mut crate::pthread_mutex_t,
201        abstime: *const crate::timespec,
202    ) -> c_int;
203
204    #[cfg(target_os = "linux")]
205    pub fn pthread_mutexattr_getprotocol(
206        attr: *const crate::pthread_mutexattr_t,
207        protocol: *mut c_int,
208    ) -> c_int;
209
210    #[cfg(any(
211        target_os = "android",
212        target_os = "l4re",
213        target_os = "linux",
214        target_vendor = "apple",
215    ))]
216    pub fn pthread_mutexattr_getpshared(
217        attr: *const crate::pthread_mutexattr_t,
218        pshared: *mut c_int,
219    ) -> c_int;
220
221    #[cfg(all(target_os = "linux", not(target_env = "ohos")))]
222    pub fn pthread_mutexattr_getrobust(
223        attr: *const crate::pthread_mutexattr_t,
224        robustness: *mut c_int,
225    ) -> c_int;
226
227    #[cfg(target_os = "linux")]
228    pub fn pthread_mutexattr_setprotocol(
229        attr: *mut crate::pthread_mutexattr_t,
230        protocol: c_int,
231    ) -> c_int;
232
233    #[cfg(any(
234        target_os = "android",
235        target_os = "emscripten",
236        target_os = "linux",
237        target_os = "l4re",
238        target_vendor = "apple",
239    ))]
240    pub fn pthread_mutexattr_setpshared(
241        attr: *mut crate::pthread_mutexattr_t,
242        pshared: c_int,
243    ) -> c_int;
244
245    #[cfg(all(target_os = "linux", not(target_env = "ohos")))]
246    pub fn pthread_mutexattr_setrobust(
247        attr: *mut crate::pthread_mutexattr_t,
248        robustness: c_int,
249    ) -> c_int;
250
251    #[cfg(any(
252        target_os = "android",
253        target_os = "emscripten",
254        target_os = "linux",
255        target_os = "l4re",
256        target_vendor = "apple",
257    ))]
258    pub fn pthread_rwlockattr_getpshared(
259        attr: *const crate::pthread_rwlockattr_t,
260        val: *mut c_int,
261    ) -> c_int;
262
263    #[cfg(any(
264        target_os = "android",
265        target_os = "emscripten",
266        target_os = "linux",
267        target_os = "l4re",
268        target_vendor = "apple",
269    ))]
270    pub fn pthread_rwlockattr_setpshared(
271        attr: *mut crate::pthread_rwlockattr_t,
272        val: c_int,
273    ) -> c_int;
274
275    // FIXME(1.0): These shoul be combined to the version that takes an optional unsafe function.
276    #[cfg(any(target_os = "l4re", target_os = "linux"))]
277    pub fn pthread_once(control: *mut crate::pthread_once_t, routine: extern "C" fn()) -> c_int;
278    #[cfg(target_vendor = "apple")]
279    pub fn pthread_once(
280        once_control: *mut crate::pthread_once_t,
281        init_routine: Option<unsafe extern "C" fn()>,
282    ) -> c_int;
283
284    #[cfg(any(
285        target_os = "android",
286        target_os = "l4re",
287        target_os = "linux",
288        target_vendor = "apple",
289    ))]
290    pub fn pthread_setschedparam(
291        native: crate::pthread_t,
292        policy: c_int,
293        param: *const crate::sched_param,
294    ) -> c_int;
295
296    #[cfg(target_os = "linux")]
297    pub fn pthread_setschedprio(native: crate::pthread_t, priority: c_int) -> c_int;
298
299    // FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
300    // in pthread.
301    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
302    pub fn pthread_sigmask(
303        how: c_int,
304        set: *const crate::sigset_t,
305        oldset: *mut crate::sigset_t,
306    ) -> c_int;
307
308    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
309    pub fn pthread_spin_destroy(lock: *mut crate::pthread_spinlock_t) -> c_int;
310
311    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
312    pub fn pthread_spin_init(lock: *mut crate::pthread_spinlock_t, pshared: c_int) -> c_int;
313
314    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
315    pub fn pthread_spin_lock(lock: *mut crate::pthread_spinlock_t) -> c_int;
316
317    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
318    pub fn pthread_spin_trylock(lock: *mut crate::pthread_spinlock_t) -> c_int;
319
320    #[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
321    pub fn pthread_spin_unlock(lock: *mut crate::pthread_spinlock_t) -> c_int;
322}