1 /* Implement a trivial subset of POSIX 1003.1-2008 pthread.h.
3 Copyright (C) 2009-2011 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* Written by Paul Eggert and Glen Lenker. */
21 #ifndef _@GUARD_PREFIX@_PTHREAD_H_
24 @PRAGMA_SYSTEM_HEADER@
28 /* The include_next requires a split double-inclusion guard. */
30 # @INCLUDE_NEXT@ @NEXT_PTHREAD_H@
33 #ifndef _@GUARD_PREFIX@_PTHREAD_H_
34 #define _@GUARD_PREFIX@_PTHREAD_H_
39 #include <sys/types.h>
42 #if ! @HAVE_PTHREAD_T@
43 # if !GNULIB_defined_pthread_types
44 typedef int pthread_t;
45 typedef int pthread_attr_t;
46 typedef int pthread_barrier_t;
47 typedef int pthread_barrierattr_t;
48 typedef int pthread_cond_t;
49 typedef int pthread_condattr_t;
50 typedef int pthread_key_t;
51 typedef int pthread_mutex_t;
52 typedef int pthread_mutexattr_t;
53 typedef int pthread_once_t;
54 typedef int pthread_rwlock_t;
55 typedef int pthread_rwlockattr_t;
56 # define GNULIB_defined_pthread_types 1
60 #ifndef PTHREAD_COND_INITIALIZER
61 #define PTHREAD_COND_INITIALIZER { 0 }
62 #define PTHREAD_MUTEX_INITIALIZER { 0 }
63 #define PTHREAD_ONCE_INIT { 0 }
64 #define PTHREAD_RWLOCK_INITIALIZER { 0 }
66 #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
68 #define PTHREAD_CANCEL_DEFERRED 0
69 #define PTHREAD_CANCEL_ASYNCHRONOUS 1
71 #define PTHREAD_CANCEL_ENABLE 0
72 #define PTHREAD_CANCEL_DISABLE 1
74 #define PTHREAD_CANCELED ((void *) -1)
76 #define PTHREAD_CREATE_JOINABLE 0
77 #define PTHREAD_CREATE_DETACHED 1
79 #define PTHREAD_INHERIT_SCHED 0
80 #define PTHREAD_EXPLICIT_SCHED 1
82 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
83 #define PTHREAD_MUTEX_NORMAL 0
84 #define PTHREAD_MUTEX_ERRORCHECK 1
85 #define PTHREAD_MUTEX_RECURSIVE 2
87 #define PTHREAD_MUTEX_STALLED 0
88 #define PTHREAD_MUTEX_ROBUST 1
90 #define PTHREAD_PRIO_NONE 0
91 #define PTHREAD_PRIO_INHERIT 1
92 #define PTHREAD_PRIO_PROTECT 2
94 #define PTHREAD_PROCESS_PRIVATE 0
95 #define PTHREAD_PROCESS_SHARED 1
97 #define PTHREAD_SCOPE_SYSTEM 0
98 #define PTHREAD_SCOPE_PROCESS 1
101 #if ! @HAVE_PTHREAD_T@
103 # if !GNULIB_defined_pthread_functions
105 /* Provide substitutes for the thread functions that should work
106 adequately on a single-threaded implementation, where
107 pthread_create always fails. The goal is to let programs compile
108 on non-pthread hosts with minimal runtime overhead.
110 Omit interfaces that have not been analyzed and for which we do not
111 know what to do, so that they elicit a compile-time error for
115 pthread_cond_destroy (pthread_cond_t *cond)
117 /* COND is never seriously used. */
122 pthread_cond_init (pthread_cond_t *restrict cond,
123 pthread_condattr_t const *restrict attr)
125 /* COND is never seriously used. */
130 pthread_cond_signal (pthread_cond_t *cond)
132 /* No threads can currently be blocked on COND. */
137 pthread_cond_wait (pthread_cond_t *restrict cond,
138 pthread_mutex_t *restrict mutex)
140 /* Properly-written applications never come here. */
146 pthread_create (pthread_t *restrict thread,
147 pthread_attr_t const *restrict attr,
148 void * (*start_routine) (void*), void *restrict arg)
150 /* Do not create a thread. */
155 pthread_exit (void *value)
157 /* There is just one thread, so the process exits. */
162 pthread_join (pthread_t thread, void **pvalue)
164 /* Properly-written applications never come here. */
170 pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
176 pthread_mutexattr_init (pthread_mutexattr_t *attr)
182 pthread_mutexattr_settype (pthread_mutexattr_t *attr, int attr_type)
188 pthread_mutex_destroy (pthread_mutex_t *mutex)
190 /* MUTEX is never seriously used. */
195 pthread_mutex_init (pthread_mutex_t *restrict mutex,
196 pthread_mutexattr_t const *restrict attr)
198 /* MUTEX is never seriously used. */
203 pthread_mutex_lock (pthread_mutex_t *mutex)
205 /* There is only one thread, so it always gets the lock. This
206 implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
211 pthread_mutex_trylock (pthread_mutex_t *mutex)
213 return pthread_mutex_lock (mutex);
217 pthread_mutex_unlock (pthread_mutex_t *mutex)
219 /* There is only one thread, so it always unlocks successfully.
220 This implementation does not support robust mutexes or
221 PTHREAD_MUTEX_ERRORCHECK. */
225 # define GNULIB_defined_pthread_functions 1
230 #if ! @HAVE_PTHREAD_SPINLOCK_T@
232 # if !GNULIB_defined_pthread_spinlock_t
234 /* Approximate spinlocks with mutexes. */
236 typedef pthread_mutex_t pthread_spinlock_t;
239 pthread_spin_init (pthread_spinlock_t *lock, int pshared)
241 return pthread_mutex_init (lock, NULL);
245 pthread_spin_destroy (pthread_spinlock_t *lock)
247 return pthread_mutex_destroy (lock);
251 pthread_spin_lock (pthread_spinlock_t *lock)
253 return pthread_mutex_lock (lock);
257 pthread_spin_trylock (pthread_spinlock_t *lock)
259 return pthread_mutex_trylock (lock);
263 pthread_spin_unlock (pthread_spinlock_t *lock)
265 return pthread_mutex_unlock (lock);
268 # define GNULIB_defined_pthread_spinlock_t 1
273 #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */
274 #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */