]>
Commit | Line | Data |
---|---|---|
c23de0aa | 1 | /* Support functionality for using threads. |
6d7e8eda | 2 | Copyright (C) 2016-2023 Free Software Foundation, Inc. |
c23de0aa FW |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
c23de0aa FW |
18 | |
19 | #ifndef SUPPORT_THREAD_H | |
20 | #define SUPPORT_THREAD_H | |
21 | ||
22 | #include <pthread.h> | |
23 | #include <sys/cdefs.h> | |
9cba3fa3 | 24 | #include <stdbool.h> |
c23de0aa FW |
25 | |
26 | __BEGIN_DECLS | |
27 | ||
28 | /* Terminate the process (with exit status 0) after SECONDS have | |
29 | elapsed, from a helper thread. The process is terminated with the | |
30 | exit function, so atexit handlers are executed. */ | |
31 | void delayed_exit (int seconds); | |
32 | ||
9cba3fa3 AZ |
33 | /* Returns true if Priority Inheritance support CLOCK_MONOTONIC. */ |
34 | bool support_mutex_pi_monotonic (void); | |
35 | ||
c23de0aa FW |
36 | /* Terminate the process (with exit status 1) if VALUE is not zero. |
37 | In that case, print a failure message to standard output mentioning | |
38 | FUNCTION. The process is terminated with the exit function, so | |
39 | atexit handlers are executed. */ | |
40 | void xpthread_check_return (const char *function, int value); | |
41 | ||
42 | /* The following functions call the corresponding libpthread functions | |
43 | and terminate the process on error. */ | |
44 | ||
45 | void xpthread_barrier_init (pthread_barrier_t *barrier, | |
46 | pthread_barrierattr_t *attr, unsigned int count); | |
47 | void xpthread_barrier_destroy (pthread_barrier_t *barrier); | |
0ce2fa69 FW |
48 | void xpthread_barrierattr_destroy (pthread_barrierattr_t *); |
49 | void xpthread_barrierattr_init (pthread_barrierattr_t *); | |
50 | void xpthread_barrierattr_setpshared (pthread_barrierattr_t *, int pshared); | |
faf0e9c8 FW |
51 | void xpthread_mutexattr_destroy (pthread_mutexattr_t *); |
52 | void xpthread_mutexattr_init (pthread_mutexattr_t *); | |
53 | void xpthread_mutexattr_setprotocol (pthread_mutexattr_t *, int); | |
54 | void xpthread_mutexattr_setpshared (pthread_mutexattr_t *, int); | |
55 | void xpthread_mutexattr_setrobust (pthread_mutexattr_t *, int); | |
56 | void xpthread_mutexattr_settype (pthread_mutexattr_t *, int); | |
57 | void xpthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *); | |
58 | void xpthread_mutex_destroy (pthread_mutex_t *); | |
c23de0aa FW |
59 | void xpthread_mutex_lock (pthread_mutex_t *mutex); |
60 | void xpthread_mutex_unlock (pthread_mutex_t *mutex); | |
faf0e9c8 | 61 | void xpthread_mutex_consistent (pthread_mutex_t *); |
c23de0aa FW |
62 | void xpthread_spin_lock (pthread_spinlock_t *lock); |
63 | void xpthread_spin_unlock (pthread_spinlock_t *lock); | |
64 | void xpthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex); | |
3bea50cc | 65 | void xpthread_cond_signal (pthread_cond_t *cond); |
c23de0aa FW |
66 | pthread_t xpthread_create (pthread_attr_t *attr, |
67 | void *(*thread_func) (void *), void *closure); | |
68 | void xpthread_detach (pthread_t thr); | |
69 | void xpthread_cancel (pthread_t thr); | |
70 | void *xpthread_join (pthread_t thr); | |
5840c75c | 71 | void xpthread_once (pthread_once_t *guard, void (*func) (void)); |
f8bf15fe CD |
72 | void xpthread_attr_destroy (pthread_attr_t *attr); |
73 | void xpthread_attr_init (pthread_attr_t *attr); | |
271ec55d | 74 | #ifdef __linux__ |
d85ad0e5 AZ |
75 | void xpthread_attr_setaffinity_np (pthread_attr_t *attr, |
76 | size_t cpusetsize, | |
77 | const cpu_set_t *cpuset); | |
271ec55d | 78 | #endif |
f8bf15fe CD |
79 | void xpthread_attr_setdetachstate (pthread_attr_t *attr, |
80 | int detachstate); | |
bc79db3f SL |
81 | void xpthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, |
82 | size_t stacksize); | |
f8bf15fe CD |
83 | void xpthread_attr_setstacksize (pthread_attr_t *attr, |
84 | size_t stacksize); | |
0edbf123 AZ |
85 | void xpthread_attr_setguardsize (pthread_attr_t *attr, |
86 | size_t guardsize); | |
c23de0aa | 87 | |
0280b390 AZ |
88 | void xpthread_kill (pthread_t thr, int signo); |
89 | ||
ecdb06cd AZ |
90 | /* Return the stack size used on support_set_small_thread_stack_size. */ |
91 | size_t support_small_thread_stack_size (void); | |
36ada9ee FW |
92 | /* Set the stack size in ATTR to a small value, but still large enough |
93 | to cover most internal glibc stack usage. */ | |
94 | void support_set_small_thread_stack_size (pthread_attr_t *attr); | |
95 | ||
96 | /* Return a pointer to a thread attribute which requests a small | |
97 | stack. The caller must not free this pointer. */ | |
98 | pthread_attr_t *support_small_stack_thread_attribute (void); | |
99 | ||
c23de0aa FW |
100 | /* This function returns non-zero if pthread_barrier_wait returned |
101 | PTHREAD_BARRIER_SERIAL_THREAD. */ | |
102 | int xpthread_barrier_wait (pthread_barrier_t *barrier); | |
103 | ||
faf8c066 CD |
104 | void xpthread_rwlock_init (pthread_rwlock_t *rwlock, |
105 | const pthread_rwlockattr_t *attr); | |
106 | void xpthread_rwlockattr_init (pthread_rwlockattr_t *attr); | |
107 | void xpthread_rwlockattr_setkind_np (pthread_rwlockattr_t *attr, int pref); | |
108 | void xpthread_rwlock_wrlock (pthread_rwlock_t *rwlock); | |
109 | void xpthread_rwlock_rdlock (pthread_rwlock_t *rwlock); | |
110 | void xpthread_rwlock_unlock (pthread_rwlock_t *rwlock); | |
5fc9ed4c | 111 | void xpthread_rwlock_destroy (pthread_rwlock_t *rwlock); |
a9bfa435 MD |
112 | pthread_key_t xpthread_key_create (void (*destr_function) (void *)); |
113 | void xpthread_key_delete (pthread_key_t key); | |
faf8c066 | 114 | |
c23de0aa FW |
115 | __END_DECLS |
116 | ||
117 | #endif /* SUPPORT_THREAD_H */ |