unicase/locale-language: Fix link dependencies.
[gnulib.git] / lib / pthread.in.h
blobc2f82455cfccdc00b2c20c3f385d725304bc9f5f
1 /* Implement a trivial subset of POSIX 1003.1-2008 pthread.h.
3 Copyright (C) 2009-2017 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)
8 any later version.
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_
22 #if __GNUC__ >= 3
23 @PRAGMA_SYSTEM_HEADER@
24 #endif
25 @PRAGMA_COLUMNS@
27 /* The include_next requires a split double-inclusion guard. */
28 #if @HAVE_PTHREAD_H@
29 # @INCLUDE_NEXT@ @NEXT_PTHREAD_H@
30 #endif
32 #ifndef _@GUARD_PREFIX@_PTHREAD_H_
33 #define _@GUARD_PREFIX@_PTHREAD_H_
35 #define __need_system_stdlib_h
36 #include <stdlib.h>
37 #undef __need_system_stdlib_h
40 /* The pthreads-win32 <pthread.h> defines a couple of broken macros. */
41 #undef asctime_r
42 #undef ctime_r
43 #undef gmtime_r
44 #undef localtime_r
45 #undef rand_r
46 #undef strtok_r
48 #include <errno.h>
49 #include <sched.h>
50 #include <sys/types.h>
51 #include <time.h>
53 #ifndef _GL_INLINE_HEADER_BEGIN
54 #error "Please include config.h first."
55 #endif
56 _GL_INLINE_HEADER_BEGIN
57 #ifndef _GL_PTHREAD_INLINE
58 # define _GL_PTHREAD_INLINE _GL_INLINE
59 #endif
61 #if ! @HAVE_PTHREAD_T@
62 # if !GNULIB_defined_pthread_types
63 typedef int pthread_t;
64 typedef int pthread_attr_t;
65 typedef int pthread_barrier_t;
66 typedef int pthread_barrierattr_t;
67 typedef int pthread_cond_t;
68 typedef int pthread_condattr_t;
69 typedef int pthread_key_t;
70 typedef int pthread_mutex_t;
71 typedef int pthread_mutexattr_t;
72 typedef int pthread_once_t;
73 typedef int pthread_rwlock_t;
74 typedef int pthread_rwlockattr_t;
75 # define GNULIB_defined_pthread_types 1
76 # endif
77 #endif
79 #ifndef PTHREAD_COND_INITIALIZER
80 #define PTHREAD_COND_INITIALIZER { 0 }
81 #define PTHREAD_MUTEX_INITIALIZER { 0 }
82 #define PTHREAD_ONCE_INIT { 0 }
83 #define PTHREAD_RWLOCK_INITIALIZER { 0 }
85 #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
87 #define PTHREAD_CANCEL_DEFERRED 0
88 #define PTHREAD_CANCEL_ASYNCHRONOUS 1
90 #define PTHREAD_CANCEL_ENABLE 0
91 #define PTHREAD_CANCEL_DISABLE 1
93 #define PTHREAD_CANCELED ((void *) -1)
95 #define PTHREAD_CREATE_JOINABLE 0
96 #define PTHREAD_CREATE_DETACHED 1
98 #define PTHREAD_INHERIT_SCHED 0
99 #define PTHREAD_EXPLICIT_SCHED 1
101 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
102 #define PTHREAD_MUTEX_NORMAL 0
103 #define PTHREAD_MUTEX_ERRORCHECK 1
104 #define PTHREAD_MUTEX_RECURSIVE 2
106 #define PTHREAD_MUTEX_STALLED 0
107 #define PTHREAD_MUTEX_ROBUST 1
109 #define PTHREAD_PRIO_NONE 0
110 #define PTHREAD_PRIO_INHERIT 1
111 #define PTHREAD_PRIO_PROTECT 2
113 #define PTHREAD_PROCESS_PRIVATE 0
114 #define PTHREAD_PROCESS_SHARED 1
116 #define PTHREAD_SCOPE_SYSTEM 0
117 #define PTHREAD_SCOPE_PROCESS 1
118 #endif
120 #if ! @HAVE_PTHREAD_T@
122 # if !GNULIB_defined_pthread_functions
124 /* Provide substitutes for the thread functions that should work
125 adequately on a single-threaded implementation, where
126 pthread_create always fails. The goal is to let programs compile
127 on non-pthread hosts with minimal runtime overhead.
129 Omit interfaces that have not been analyzed and for which we do not
130 know what to do, so that they elicit a compile-time error for
131 now. */
133 _GL_PTHREAD_INLINE int
134 pthread_cond_destroy (pthread_cond_t *cond)
136 /* COND is never seriously used. */
137 return 0;
140 _GL_PTHREAD_INLINE int
141 pthread_cond_init (pthread_cond_t *restrict cond,
142 pthread_condattr_t const *restrict attr)
144 /* COND is never seriously used. */
145 return 0;
148 _GL_PTHREAD_INLINE int
149 pthread_cond_signal (pthread_cond_t *cond)
151 /* No threads can currently be blocked on COND. */
152 return 0;
155 _GL_PTHREAD_INLINE int
156 pthread_cond_wait (pthread_cond_t *restrict cond,
157 pthread_mutex_t *restrict mutex)
159 /* Properly-written applications never come here. */
160 abort ();
161 return 0;
164 _GL_PTHREAD_INLINE int
165 pthread_create (pthread_t *restrict thread,
166 pthread_attr_t const *restrict attr,
167 void * (*start_routine) (void*), void *restrict arg)
169 /* Do not create a thread. */
170 return EAGAIN;
173 _GL_PTHREAD_INLINE void
174 pthread_exit (void *value)
176 /* There is just one thread, so the process exits. */
177 exit (0);
180 _GL_PTHREAD_INLINE int
181 pthread_join (pthread_t thread, void **pvalue)
183 /* Properly-written applications never come here. */
184 abort ();
185 return 0;
188 _GL_PTHREAD_INLINE int
189 pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
191 return 0;
194 _GL_PTHREAD_INLINE int
195 pthread_mutexattr_init (pthread_mutexattr_t *attr)
197 return 0;
200 _GL_PTHREAD_INLINE int
201 pthread_mutexattr_settype (pthread_mutexattr_t *attr, int attr_type)
203 return 0;
206 _GL_PTHREAD_INLINE int
207 pthread_mutex_destroy (pthread_mutex_t *mutex)
209 /* MUTEX is never seriously used. */
210 return 0;
213 _GL_PTHREAD_INLINE int
214 pthread_mutex_init (pthread_mutex_t *restrict mutex,
215 pthread_mutexattr_t const *restrict attr)
217 /* MUTEX is never seriously used. */
218 return 0;
221 _GL_PTHREAD_INLINE int
222 pthread_mutex_lock (pthread_mutex_t *mutex)
224 /* There is only one thread, so it always gets the lock. This
225 implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
226 return 0;
229 _GL_PTHREAD_INLINE int
230 pthread_mutex_trylock (pthread_mutex_t *mutex)
232 return pthread_mutex_lock (mutex);
235 _GL_PTHREAD_INLINE int
236 pthread_mutex_unlock (pthread_mutex_t *mutex)
238 /* There is only one thread, so it always unlocks successfully.
239 This implementation does not support robust mutexes or
240 PTHREAD_MUTEX_ERRORCHECK. */
241 return 0;
244 # define GNULIB_defined_pthread_functions 1
245 # endif
247 #endif
249 #if ! @HAVE_PTHREAD_SPINLOCK_T@
251 # if !GNULIB_defined_pthread_spinlock_t
253 /* Approximate spinlocks with mutexes. */
255 typedef pthread_mutex_t pthread_spinlock_t;
257 _GL_PTHREAD_INLINE int
258 pthread_spin_init (pthread_spinlock_t *lock, int pshared)
260 return pthread_mutex_init (lock, NULL);
263 _GL_PTHREAD_INLINE int
264 pthread_spin_destroy (pthread_spinlock_t *lock)
266 return pthread_mutex_destroy (lock);
269 _GL_PTHREAD_INLINE int
270 pthread_spin_lock (pthread_spinlock_t *lock)
272 return pthread_mutex_lock (lock);
275 _GL_PTHREAD_INLINE int
276 pthread_spin_trylock (pthread_spinlock_t *lock)
278 return pthread_mutex_trylock (lock);
281 _GL_PTHREAD_INLINE int
282 pthread_spin_unlock (pthread_spinlock_t *lock)
284 return pthread_mutex_unlock (lock);
287 # define GNULIB_defined_pthread_spinlock_t 1
288 # endif
290 #endif
292 _GL_INLINE_HEADER_END
294 #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */
295 #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */