1 /* Implement a trivial subset of POSIX 1003.1-2008 pthread.h.
3 Copyright (C) 2009, 2010 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 _GL_PTHREAD_H_
22 #define _GL_PTHREAD_H_
27 #include <sys/types.h>
30 #ifndef HAVE_PTHREAD_T
31 typedef int pthread_t;
32 typedef int pthread_attr_t;
33 typedef int pthread_barrier_t;
34 typedef int pthread_barrierattr_t;
35 typedef int pthread_cond_t;
36 typedef int pthread_condattr_t;
37 typedef int pthread_key_t;
38 typedef int pthread_mutex_t;
39 typedef int pthread_mutexattr_t;
40 typedef int pthread_once_t;
41 typedef int pthread_rwlock_t;
42 typedef int pthread_rwlockattr_t;
43 typedef int pthread_spinlock_t;
46 #define PTHREAD_COND_INITIALIZER { 0 }
47 #define PTHREAD_MUTEX_INITIALIZER { 0 }
48 #define PTHREAD_ONCE_INIT { 0 }
49 #define PTHREAD_RWLOCK_INITIALIZER { 0 }
51 #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
53 #define PTHREAD_CANCEL_DEFERRED 0
54 #define PTHREAD_CANCEL_ASYNCHRONOUS 1
56 #define PTHREAD_CANCEL_ENABLE 0
57 #define PTHREAD_CANCEL_DISABLE 1
59 #define PTHREAD_CANCELED ((void *) -1)
61 #define PTHREAD_CREATE_JOINABLE 0
62 #define PTHREAD_CREATE_DETACHED 1
64 #define PTHREAD_INHERIT_SCHED 0
65 #define PTHREAD_EXPLICIT_SCHED 1
67 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
68 #define PTHREAD_MUTEX_NORMAL 0
69 #define PTHREAD_MUTEX_ERRORCHECK 1
70 #define PTHREAD_MUTEX_RECURSIVE 2
72 #define PTHREAD_MUTEX_STALLED 0
73 #define PTHREAD_MUTEX_ROBUST 1
75 #define PTHREAD_PRIO_NONE 0
76 #define PTHREAD_PRIO_INHERIT 1
77 #define PTHREAD_PRIO_PROTECT 2
79 #define PTHREAD_PROCESS_PRIVATE 0
80 #define PTHREAD_PROCESS_SHARED 1
82 #define PTHREAD_SCOPE_SYSTEM 0
83 #define PTHREAD_SCOPE_PROCESS 1
85 /* Provide substitutes for the thread functions that should work
86 adequately on a single-threaded implementation, where
87 pthread_create always fails. The goal is to let programs compile
88 on non-pthread hosts with minimal runtime overhead.
90 Omit interfaces that have not been analyzed and for which we do not
91 know what to do, so that they elicit a compile-time error for
95 pthread_cond_destroy (pthread_cond_t *cond)
97 /* COND is never seriously used. */
102 pthread_cond_init (pthread_cond_t *restrict cond,
103 pthread_condattr_t const *restrict attr)
105 /* COND is never seriously used. */
110 pthread_cond_signal (pthread_cond_t *cond)
112 /* No threads can currently be blocked on COND. */
117 pthread_cond_wait (pthread_cond_t *restrict cond,
118 pthread_mutex_t *restrict mutex)
120 /* Properly-written applications never come here. */
126 pthread_create (pthread_t *restrict thread,
127 pthread_attr_t const *restrict attr,
128 void * (*start_routine) (void*), void *restrict arg)
130 /* Do not create a thread. */
135 pthread_exit (void *value)
137 /* There is just one thread, so the process exits. */
142 pthread_join (pthread_t thread, void **pvalue)
144 /* Properly-written applications never come here. */
150 pthread_mutex_destroy (pthread_mutex_t *mutex)
152 /* MUTEX is never seriously used. */
157 pthread_mutex_init (pthread_mutex_t *restrict mutex,
158 pthread_mutexattr_t const *restrict attr)
160 /* MUTEX is never seriously used. */
165 pthread_mutex_lock (pthread_mutex_t *mutex)
167 /* There is only one thread, so it always gets the lock. This
168 implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
173 pthread_mutex_unlock (pthread_mutex_t *mutex)
175 /* There is only one thread, so it always unlocks successfully.
176 This implementation does not support robust mutexes or
177 PTHREAD_MUTEX_ERRORCHECK. */
182 pthread_spin_init (pthread_spinlock_t *lock, int pshared)
184 /* LOCK is never seriously used. */
189 pthread_spin_lock (pthread_spinlock_t *lock)
191 /* Only one thread, so it always gets the lock. */
196 pthread_spin_trylock (pthread_spinlock_t *lock)
198 /* Only one thread, so it always gets the lock. Assume that a
199 thread never tries a lock that it already holds. */
204 pthread_spin_unlock (pthread_spinlock_t *lock)
206 /* Only one thread, so spin locks are no-ops. */
210 #endif /* _GL_PTHREAD_H_ */