Mercurial > hg > octave-shane > gnulib-hg
comparison lib/pthread.in.h @ 13467:b3e78c51aab6
pthread: Add enough so that coreutils/src/sort.c compiles.
* lib/pthread.in.h: Add self to author comment. Conditionalize on
_GL_PTHREAD_H, not PTHREAD_H_, for consistency with the rest of
gnulib. Include <sched.h> and <time.h>, as per POSIX.
Include <sys/types.h>, in case it defines pthread_t.
(pthread_t, pthread_attr_t, pthread_barrier_t, pthread_barrierattr_t):
(pthread_cond_t, pthread_condattr_t, pthread_key_t, pthread_mutex_t):
(pthread_mutexattr_t, pthread_once_t, pthread_rwlock_t):
(pthread_rwlockattr_t, pthread_spinlock_t):
New typedefs, if HAVE_PTHREAD_T is not defined.
(PTHREAD_COND_INITIALIZER, PTHREAD_MUTEX_INITIALIZER):
(PTHREAD_ONCE_INIT, PTHREAD_RWLOCK_INITIALIZER):
(PTHREAD_BARRIER_SERIAL_THREAD, PTHREAD_CANCEL_DEFERRED):
(PTHREAD_CANCEL_ASYNCHRONOUS, PTHREAD_CANCEL_ENABLE):
(PTHREAD_CANCEL_DISABLE, PTHREAD_CANCELED, PTHREAD_CREATE_JOINABLE):
(PTHREAD_CREATE_DETACHED, PTHREAD_INHERIT_SCHED):
(PTHREAD_EXPLICIT_SCHED, PTHREAD_MUTEX_DEFAULT, PTHREAD_MUTEX_NORMAL):
(PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_RECURSIVE):
(PTHREAD_MUTEX_STALLED, PTHREAD_MUTEX_ROBUST, PTHREAD_PRIO_NONE):
(PTHREAD_PRIO_INHERIT, PTHREAD_PRIO_PROTECT, PTHREAD_PROCESS_PRIVATE):
(PTHREAD_PROCESS_SHARED, PTHREAD_SCOPE_SYSTEM, PTHREAD_SCOPE_PROCESS):
New macros.
(pthread_cond_destroy, pthread_cond_init, pthread_cond_signal):
(pthread_cond_wait, pthread_exit, pthread_mutex_destroy):
(pthread_mutex_init, pthread_mutex_lock, pthread_mutex_unlock):
(pthread_spin_init, pthread_spin_lock, pthread_spin_trylock);
(pthread_spin_unlock): New dummy functions.
(pthread_create): Return EAGAIN; don't set errno.
* m4/pthread.m4 (gl_PTHREAD_CHECK): Check for pthread_t, and
require AC_C_INLINE.
* modules/pthread (Depends-on): Add sched, time.
(pthread.h): Use AM_V_GEN.
author | Paul R. Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 13 Jul 2010 15:55:36 -0700 |
parents | c2cbabec01dd |
children | 8a0b8adde2be |
comparison
equal
deleted
inserted
replaced
13466:00760b212392 | 13467:b3e78c51aab6 |
---|---|
1 /* Implement a trivial subset of the pthreads library. | 1 /* Implement a trivial subset of POSIX 1003.1-2008 pthread.h. |
2 | 2 |
3 Copyright (C) 2009, 2010 Free Software Foundation, Inc. | 3 Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
4 | 4 |
5 This program is free software; you can redistribute it and/or modify | 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 | 6 it under the terms of the GNU General Public License as published by |
14 | 14 |
15 You should have received a copy of the GNU General Public License | 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, | 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. */ | 17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
18 | 18 |
19 /* Written by Glen Lenker. */ | 19 /* Written by Paul Eggert and Glen Lenker. */ |
20 | 20 |
21 #ifndef PTHREAD_H_ | 21 #ifndef _GL_PTHREAD_H_ |
22 # define PTHREAD_H_ | 22 #define _GL_PTHREAD_H_ |
23 | 23 |
24 # include <errno.h> | 24 #include <errno.h> |
25 # include <stdlib.h> | 25 #include <stdlib.h> |
26 | 26 #include <sched.h> |
27 typedef int pthread_t; | 27 #include <sys/types.h> |
28 typedef int pthread_attr_t; | 28 #include <time.h> |
29 | 29 |
30 static int | 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; | |
44 #endif | |
45 | |
46 #define PTHREAD_COND_INITIALIZER { 0 } | |
47 #define PTHREAD_MUTEX_INITIALIZER { 0 } | |
48 #define PTHREAD_ONCE_INIT { 0 } | |
49 #define PTHREAD_RWLOCK_INITIALIZER { 0 } | |
50 | |
51 #define PTHREAD_BARRIER_SERIAL_THREAD (-1) | |
52 | |
53 #define PTHREAD_CANCEL_DEFERRED 0 | |
54 #define PTHREAD_CANCEL_ASYNCHRONOUS 1 | |
55 | |
56 #define PTHREAD_CANCEL_ENABLE 0 | |
57 #define PTHREAD_CANCEL_DISABLE 1 | |
58 | |
59 #define PTHREAD_CANCELED ((void *) -1) | |
60 | |
61 #define PTHREAD_CREATE_JOINABLE 0 | |
62 #define PTHREAD_CREATE_DETACHED 1 | |
63 | |
64 #define PTHREAD_INHERIT_SCHED 0 | |
65 #define PTHREAD_EXPLICIT_SCHED 1 | |
66 | |
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 | |
71 | |
72 #define PTHREAD_MUTEX_STALLED 0 | |
73 #define PTHREAD_MUTEX_ROBUST 1 | |
74 | |
75 #define PTHREAD_PRIO_NONE 0 | |
76 #define PTHREAD_PRIO_INHERIT 1 | |
77 #define PTHREAD_PRIO_PROTECT 2 | |
78 | |
79 #define PTHREAD_PROCESS_PRIVATE 0 | |
80 #define PTHREAD_PROCESS_SHARED 1 | |
81 | |
82 #define PTHREAD_SCOPE_SYSTEM 0 | |
83 #define PTHREAD_SCOPE_PROCESS 1 | |
84 | |
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. | |
89 | |
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 | |
92 now. */ | |
93 | |
94 static inline int | |
95 pthread_cond_destroy (pthread_cond_t *cond) | |
96 { | |
97 /* COND is never seriously used. */ | |
98 return 0; | |
99 } | |
100 | |
101 static inline int | |
102 pthread_cond_init (pthread_cond_t *restrict cond, | |
103 pthread_condattr_t const *restrict attr) | |
104 { | |
105 /* COND is never seriously used. */ | |
106 return 0; | |
107 } | |
108 | |
109 static inline int | |
110 pthread_cond_signal (pthread_cond_t *cond) | |
111 { | |
112 /* No threads can currently be blocked on COND. */ | |
113 return 0; | |
114 } | |
115 | |
116 static inline int | |
117 pthread_cond_wait (pthread_cond_t *restrict cond, | |
118 pthread_mutex_t *restrict mutex) | |
119 { | |
120 /* Properly-written applications never come here. */ | |
121 abort (); | |
122 return 0; | |
123 } | |
124 | |
125 static inline int | |
31 pthread_create (pthread_t *restrict thread, | 126 pthread_create (pthread_t *restrict thread, |
32 const pthread_attr_t *restrict attr, | 127 pthread_attr_t const *restrict attr, |
33 void *(*start_routine)(void*), void *restrict arg) | 128 void * (*start_routine) (void*), void *restrict arg) |
34 { | 129 { |
35 errno = EAGAIN; | 130 /* Do not create a thread. */ |
36 return -1; | 131 return EAGAIN; |
37 } | 132 } |
38 | 133 |
39 static int | 134 static inline void |
40 pthread_join (pthread_t thread, void **value_ptr) | 135 pthread_exit (void *value) |
41 { | 136 { |
137 /* There is just one thread, so the process exits. */ | |
138 exit (0); | |
139 } | |
140 | |
141 static inline int | |
142 pthread_join (pthread_t thread, void **pvalue) | |
143 { | |
144 /* Properly-written applications never come here. */ | |
42 abort (); | 145 abort (); |
43 return -1; | 146 return 0; |
44 } | 147 } |
45 | 148 |
46 #endif /* PTHREAD_H_ */ | 149 static inline int |
150 pthread_mutex_destroy (pthread_mutex_t *mutex) | |
151 { | |
152 /* MUTEX is never seriously used. */ | |
153 return 0; | |
154 } | |
155 | |
156 static inline int | |
157 pthread_mutex_init (pthread_mutex_t *restrict mutex, | |
158 pthread_mutexattr_t const *restrict attr) | |
159 { | |
160 /* MUTEX is never seriously used. */ | |
161 return 0; | |
162 } | |
163 | |
164 static inline int | |
165 pthread_mutex_lock (pthread_mutex_t *mutex) | |
166 { | |
167 /* There is only one thread, so it always gets the lock. This | |
168 implementation does not support PTHREAD_MUTEX_ERRORCHECK. */ | |
169 return 0; | |
170 } | |
171 | |
172 static inline int | |
173 pthread_mutex_unlock (pthread_mutex_t *mutex) | |
174 { | |
175 /* There is only one thread, so it always unlocks successfully. | |
176 This implementation does not support robust mutexes or | |
177 PTHREAD_MUTEX_ERRORCHECK. */ | |
178 return 0; | |
179 } | |
180 | |
181 static inline int | |
182 pthread_spin_init (pthread_spinlock_t *lock, int pshared) | |
183 { | |
184 /* LOCK is never seriously used. */ | |
185 return 0; | |
186 } | |
187 | |
188 static inline int | |
189 pthread_spin_lock (pthread_spinlock_t *lock) | |
190 { | |
191 /* Only one thread, so it always gets the lock. */ | |
192 return 0; | |
193 } | |
194 | |
195 static inline int | |
196 pthread_spin_trylock (pthread_spinlock_t *lock) | |
197 { | |
198 /* Only one thread, so it always gets the lock. Assume that a | |
199 thread never tries a lock that it already holds. */ | |
200 return 0; | |
201 } | |
202 | |
203 static inline int | |
204 pthread_spin_unlock (pthread_spinlock_t *lock) | |
205 { | |
206 /* Only one thread, so spin locks are no-ops. */ | |
207 return 0; | |
208 } | |
209 | |
210 #endif /* _GL_PTHREAD_H_ */ |