1/* Support functionality for using threads.
2 Copyright (C) 2016-2024 Free Software Foundation, Inc.
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
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef SUPPORT_THREAD_H
20#define SUPPORT_THREAD_H
21
22#include <pthread.h>
23#include <sys/cdefs.h>
24#include <stdbool.h>
25
26__BEGIN_DECLS
27
28/* Terminate the process (with exit (0)) after SECONDS have elapsed,
29 from a helper thread. The process is terminated with the exit
30 function, so atexit handlers are executed. */
31void delayed_exit (int seconds);
32
33/* Like delayed_exit, but use _exit (0). */
34void delayed__exit (int seconds);
35
36/* Returns true if Priority Inheritance support CLOCK_MONOTONIC. */
37bool support_mutex_pi_monotonic (void);
38
39/* Terminate the process (with exit status 1) if VALUE is not zero.
40 In that case, print a failure message to standard output mentioning
41 FUNCTION. The process is terminated with the exit function, so
42 atexit handlers are executed. */
43void xpthread_check_return (const char *function, int value);
44
45/* The following functions call the corresponding libpthread functions
46 and terminate the process on error. */
47
48void xpthread_barrier_init (pthread_barrier_t *barrier,
49 pthread_barrierattr_t *attr, unsigned int count);
50void xpthread_barrier_destroy (pthread_barrier_t *barrier);
51void xpthread_barrierattr_destroy (pthread_barrierattr_t *);
52void xpthread_barrierattr_init (pthread_barrierattr_t *);
53void xpthread_barrierattr_setpshared (pthread_barrierattr_t *, int pshared);
54void xpthread_mutexattr_destroy (pthread_mutexattr_t *);
55void xpthread_mutexattr_init (pthread_mutexattr_t *);
56void xpthread_mutexattr_setprotocol (pthread_mutexattr_t *, int);
57void xpthread_mutexattr_setpshared (pthread_mutexattr_t *, int);
58void xpthread_mutexattr_setrobust (pthread_mutexattr_t *, int);
59void xpthread_mutexattr_settype (pthread_mutexattr_t *, int);
60void xpthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *);
61void xpthread_mutex_destroy (pthread_mutex_t *);
62void xpthread_mutex_lock (pthread_mutex_t *mutex);
63void xpthread_mutex_unlock (pthread_mutex_t *mutex);
64void xpthread_mutex_consistent (pthread_mutex_t *);
65void xpthread_spin_lock (pthread_spinlock_t *lock);
66void xpthread_spin_unlock (pthread_spinlock_t *lock);
67void xpthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex);
68void xpthread_cond_signal (pthread_cond_t *cond);
69pthread_t xpthread_create (pthread_attr_t *attr,
70 void *(*thread_func) (void *), void *closure);
71void xpthread_detach (pthread_t thr);
72void xpthread_cancel (pthread_t thr);
73void *xpthread_join (pthread_t thr);
74void xpthread_once (pthread_once_t *guard, void (*func) (void));
75void xpthread_attr_destroy (pthread_attr_t *attr);
76void xpthread_attr_init (pthread_attr_t *attr);
77#ifdef __linux__
78void xpthread_attr_setaffinity_np (pthread_attr_t *attr,
79 size_t cpusetsize,
80 const cpu_set_t *cpuset);
81#endif
82void xpthread_attr_setdetachstate (pthread_attr_t *attr,
83 int detachstate);
84void xpthread_attr_setstack (pthread_attr_t *attr, void *stackaddr,
85 size_t stacksize);
86void xpthread_attr_setstacksize (pthread_attr_t *attr,
87 size_t stacksize);
88void xpthread_attr_setguardsize (pthread_attr_t *attr,
89 size_t guardsize);
90
91void xpthread_kill (pthread_t thr, int signo);
92
93/* Return the stack size used on support_set_small_thread_stack_size. */
94size_t support_small_thread_stack_size (void);
95/* Set the stack size in ATTR to a small value, but still large enough
96 to cover most internal glibc stack usage. */
97void support_set_small_thread_stack_size (pthread_attr_t *attr);
98
99/* Return a pointer to a thread attribute which requests a small
100 stack. The caller must not free this pointer. */
101pthread_attr_t *support_small_stack_thread_attribute (void);
102
103/* This function returns non-zero if pthread_barrier_wait returned
104 PTHREAD_BARRIER_SERIAL_THREAD. */
105int xpthread_barrier_wait (pthread_barrier_t *barrier);
106
107void xpthread_rwlock_init (pthread_rwlock_t *rwlock,
108 const pthread_rwlockattr_t *attr);
109void xpthread_rwlockattr_init (pthread_rwlockattr_t *attr);
110void xpthread_rwlockattr_setkind_np (pthread_rwlockattr_t *attr, int pref);
111void xpthread_rwlock_wrlock (pthread_rwlock_t *rwlock);
112void xpthread_rwlock_rdlock (pthread_rwlock_t *rwlock);
113void xpthread_rwlock_unlock (pthread_rwlock_t *rwlock);
114void xpthread_rwlock_destroy (pthread_rwlock_t *rwlock);
115pthread_key_t xpthread_key_create (void (*destr_function) (void *));
116void xpthread_key_delete (pthread_key_t key);
117
118__END_DECLS
119
120#endif /* SUPPORT_THREAD_H */
121

source code of glibc/support/xthread.h