1 /* Implement a trivial subset of POSIX 1003.1-2008 pthread.h.
3 Copyright (C) 2009-2013 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, see <http://www.gnu.org/licenses/>. */
18 /* Written by Paul Eggert and Glen Lenker. */
20 #ifndef _@GUARD_PREFIX@_PTHREAD_H_
23 @PRAGMA_SYSTEM_HEADER@
27 /* The include_next requires a split double-inclusion guard. */
29 # @INCLUDE_NEXT@ @NEXT_PTHREAD_H@
32 #ifndef _@GUARD_PREFIX@_PTHREAD_H_
33 #define _@GUARD_PREFIX@_PTHREAD_H_
35 #define __need_system_stdlib_h
37 #undef __need_system_stdlib_h
41 #include <sys/types.h>
44 _GL_INLINE_HEADER_BEGIN
45 #ifndef _GL_PTHREAD_INLINE
46 # define _GL_PTHREAD_INLINE _GL_INLINE
49 #if ! @HAVE_PTHREAD_T@
50 # if !GNULIB_defined_pthread_types
51 typedef int pthread_t;
52 typedef int pthread_attr_t;
53 typedef int pthread_barrier_t;
54 typedef int pthread_barrierattr_t;
55 typedef int pthread_cond_t;
56 typedef int pthread_condattr_t;
57 typedef int pthread_key_t;
58 typedef int pthread_mutex_t;
59 typedef int pthread_mutexattr_t;
60 typedef int pthread_once_t;
61 typedef int pthread_rwlock_t;
62 typedef int pthread_rwlockattr_t;
63 # define GNULIB_defined_pthread_types 1
67 #ifndef PTHREAD_COND_INITIALIZER
68 #define PTHREAD_COND_INITIALIZER { 0 }
69 #define PTHREAD_MUTEX_INITIALIZER { 0 }
70 #define PTHREAD_ONCE_INIT { 0 }
71 #define PTHREAD_RWLOCK_INITIALIZER { 0 }
73 #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
75 #define PTHREAD_CANCEL_DEFERRED 0
76 #define PTHREAD_CANCEL_ASYNCHRONOUS 1
78 #define PTHREAD_CANCEL_ENABLE 0
79 #define PTHREAD_CANCEL_DISABLE 1
81 #define PTHREAD_CANCELED ((void *) -1)
83 #define PTHREAD_CREATE_JOINABLE 0
84 #define PTHREAD_CREATE_DETACHED 1
86 #define PTHREAD_INHERIT_SCHED 0
87 #define PTHREAD_EXPLICIT_SCHED 1
89 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
90 #define PTHREAD_MUTEX_NORMAL 0
91 #define PTHREAD_MUTEX_ERRORCHECK 1
92 #define PTHREAD_MUTEX_RECURSIVE 2
94 #define PTHREAD_MUTEX_STALLED 0
95 #define PTHREAD_MUTEX_ROBUST 1
97 #define PTHREAD_PRIO_NONE 0
98 #define PTHREAD_PRIO_INHERIT 1
99 #define PTHREAD_PRIO_PROTECT 2
101 #define PTHREAD_PROCESS_PRIVATE 0
102 #define PTHREAD_PROCESS_SHARED 1
104 #define PTHREAD_SCOPE_SYSTEM 0
105 #define PTHREAD_SCOPE_PROCESS 1
108 #if ! @HAVE_PTHREAD_T@
110 # if !GNULIB_defined_pthread_functions
112 /* Provide substitutes for the thread functions that should work
113 adequately on a single-threaded implementation, where
114 pthread_create always fails. The goal is to let programs compile
115 on non-pthread hosts with minimal runtime overhead.
117 Omit interfaces that have not been analyzed and for which we do not
118 know what to do, so that they elicit a compile-time error for
121 _GL_PTHREAD_INLINE int
122 pthread_cond_destroy (pthread_cond_t *cond)
124 /* COND is never seriously used. */
128 _GL_PTHREAD_INLINE int
129 pthread_cond_init (pthread_cond_t *restrict cond,
130 pthread_condattr_t const *restrict attr)
132 /* COND is never seriously used. */
136 _GL_PTHREAD_INLINE int
137 pthread_cond_signal (pthread_cond_t *cond)
139 /* No threads can currently be blocked on COND. */
143 _GL_PTHREAD_INLINE int
144 pthread_cond_wait (pthread_cond_t *restrict cond,
145 pthread_mutex_t *restrict mutex)
147 /* Properly-written applications never come here. */
152 _GL_PTHREAD_INLINE int
153 pthread_create (pthread_t *restrict thread,
154 pthread_attr_t const *restrict attr,
155 void * (*start_routine) (void*), void *restrict arg)
157 /* Do not create a thread. */
161 _GL_PTHREAD_INLINE void
162 pthread_exit (void *value)
164 /* There is just one thread, so the process exits. */
168 _GL_PTHREAD_INLINE int
169 pthread_join (pthread_t thread, void **pvalue)
171 /* Properly-written applications never come here. */
176 _GL_PTHREAD_INLINE int
177 pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
182 _GL_PTHREAD_INLINE int
183 pthread_mutexattr_init (pthread_mutexattr_t *attr)
188 _GL_PTHREAD_INLINE int
189 pthread_mutexattr_settype (pthread_mutexattr_t *attr, int attr_type)
194 _GL_PTHREAD_INLINE int
195 pthread_mutex_destroy (pthread_mutex_t *mutex)
197 /* MUTEX is never seriously used. */
201 _GL_PTHREAD_INLINE int
202 pthread_mutex_init (pthread_mutex_t *restrict mutex,
203 pthread_mutexattr_t const *restrict attr)
205 /* MUTEX is never seriously used. */
209 _GL_PTHREAD_INLINE int
210 pthread_mutex_lock (pthread_mutex_t *mutex)
212 /* There is only one thread, so it always gets the lock. This
213 implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
217 _GL_PTHREAD_INLINE int
218 pthread_mutex_trylock (pthread_mutex_t *mutex)
220 return pthread_mutex_lock (mutex);
223 _GL_PTHREAD_INLINE int
224 pthread_mutex_unlock (pthread_mutex_t *mutex)
226 /* There is only one thread, so it always unlocks successfully.
227 This implementation does not support robust mutexes or
228 PTHREAD_MUTEX_ERRORCHECK. */
232 # define GNULIB_defined_pthread_functions 1
237 #if ! @HAVE_PTHREAD_SPINLOCK_T@
239 # if !GNULIB_defined_pthread_spinlock_t
241 /* Approximate spinlocks with mutexes. */
243 typedef pthread_mutex_t pthread_spinlock_t;
245 _GL_PTHREAD_INLINE int
246 pthread_spin_init (pthread_spinlock_t *lock, int pshared)
248 return pthread_mutex_init (lock, NULL);
251 _GL_PTHREAD_INLINE int
252 pthread_spin_destroy (pthread_spinlock_t *lock)
254 return pthread_mutex_destroy (lock);
257 _GL_PTHREAD_INLINE int
258 pthread_spin_lock (pthread_spinlock_t *lock)
260 return pthread_mutex_lock (lock);
263 _GL_PTHREAD_INLINE int
264 pthread_spin_trylock (pthread_spinlock_t *lock)
266 return pthread_mutex_trylock (lock);
269 _GL_PTHREAD_INLINE int
270 pthread_spin_unlock (pthread_spinlock_t *lock)
272 return pthread_mutex_unlock (lock);
275 # define GNULIB_defined_pthread_spinlock_t 1
280 _GL_INLINE_HEADER_END
282 #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */
283 #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */