1/* Support functionality for using threads.
2 Copyright (C) 2016-2018 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 <http://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
25__BEGIN_DECLS
26
27/* Terminate the process (with exit status 0) after SECONDS have
28 elapsed, from a helper thread. The process is terminated with the
29 exit function, so atexit handlers are executed. */
30void delayed_exit (int seconds);
31
32/* Terminate the process (with exit status 1) if VALUE is not zero.
33 In that case, print a failure message to standard output mentioning
34 FUNCTION. The process is terminated with the exit function, so
35 atexit handlers are executed. */
36void xpthread_check_return (const char *function, int value);
37
38/* The following functions call the corresponding libpthread functions
39 and terminate the process on error. */
40
41void xpthread_barrier_init (pthread_barrier_t *barrier,
42 pthread_barrierattr_t *attr, unsigned int count);
43void xpthread_barrier_destroy (pthread_barrier_t *barrier);
44void xpthread_barrierattr_destroy (pthread_barrierattr_t *);
45void xpthread_barrierattr_init (pthread_barrierattr_t *);
46void xpthread_barrierattr_setpshared (pthread_barrierattr_t *, int pshared);
47void xpthread_mutexattr_destroy (pthread_mutexattr_t *);
48void xpthread_mutexattr_init (pthread_mutexattr_t *);
49void xpthread_mutexattr_setprotocol (pthread_mutexattr_t *, int);
50void xpthread_mutexattr_setpshared (pthread_mutexattr_t *, int);
51void xpthread_mutexattr_setrobust (pthread_mutexattr_t *, int);
52void xpthread_mutexattr_settype (pthread_mutexattr_t *, int);
53void xpthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *);
54void xpthread_mutex_destroy (pthread_mutex_t *);
55void xpthread_mutex_lock (pthread_mutex_t *mutex);
56void xpthread_mutex_unlock (pthread_mutex_t *mutex);
57void xpthread_mutex_consistent (pthread_mutex_t *);
58void xpthread_spin_lock (pthread_spinlock_t *lock);
59void xpthread_spin_unlock (pthread_spinlock_t *lock);
60void xpthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex);
61pthread_t xpthread_create (pthread_attr_t *attr,
62 void *(*thread_func) (void *), void *closure);
63void xpthread_detach (pthread_t thr);
64void xpthread_cancel (pthread_t thr);
65void *xpthread_join (pthread_t thr);
66void xpthread_once (pthread_once_t *guard, void (*func) (void));
67void xpthread_attr_destroy (pthread_attr_t *attr);
68void xpthread_attr_init (pthread_attr_t *attr);
69void xpthread_attr_setdetachstate (pthread_attr_t *attr,
70 int detachstate);
71void xpthread_attr_setstacksize (pthread_attr_t *attr,
72 size_t stacksize);
73void xpthread_attr_setguardsize (pthread_attr_t *attr,
74 size_t guardsize);
75
76/* This function returns non-zero if pthread_barrier_wait returned
77 PTHREAD_BARRIER_SERIAL_THREAD. */
78int xpthread_barrier_wait (pthread_barrier_t *barrier);
79
80void xpthread_rwlock_init (pthread_rwlock_t *rwlock,
81 const pthread_rwlockattr_t *attr);
82void xpthread_rwlockattr_init (pthread_rwlockattr_t *attr);
83void xpthread_rwlockattr_setkind_np (pthread_rwlockattr_t *attr, int pref);
84void xpthread_rwlock_wrlock (pthread_rwlock_t *rwlock);
85void xpthread_rwlock_rdlock (pthread_rwlock_t *rwlock);
86void xpthread_rwlock_unlock (pthread_rwlock_t *rwlock);
87
88__END_DECLS
89
90#endif /* SUPPORT_THREAD_H */
91