1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/* Implement a trivial subset of POSIX 1003.1-2008 pthread.h.
Copyright (C) 2009-2015 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert and Glen Lenker. */
#ifndef _@GUARD_PREFIX@_PTHREAD_H_
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
@PRAGMA_COLUMNS@
/* The include_next requires a split double-inclusion guard. */
#if @HAVE_PTHREAD_H@
# @INCLUDE_NEXT@ @NEXT_PTHREAD_H@
#endif
#ifndef _@GUARD_PREFIX@_PTHREAD_H_
#define _@GUARD_PREFIX@_PTHREAD_H_
#define __need_system_stdlib_h
#include <stdlib.h>
#undef __need_system_stdlib_h
/* The pthreads-win32 <pthread.h> defines a couple of broken macros. */
#undef asctime_r
#undef ctime_r
#undef gmtime_r
#undef localtime_r
#undef rand_r
#undef strtok_r
#include <errno.h>
#include <sched.h>
#include <sys/types.h>
#include <time.h>
#ifndef _GL_INLINE_HEADER_BEGIN
#error "Please include config.h first."
#endif
_GL_INLINE_HEADER_BEGIN
#ifndef _GL_PTHREAD_INLINE
# define _GL_PTHREAD_INLINE _GL_INLINE
#endif
#if ! @HAVE_PTHREAD_T@
# if !GNULIB_defined_pthread_types
typedef int pthread_t;
typedef int pthread_attr_t;
typedef int pthread_barrier_t;
typedef int pthread_barrierattr_t;
typedef int pthread_cond_t;
typedef int pthread_condattr_t;
typedef int pthread_key_t;
typedef int pthread_mutex_t;
typedef int pthread_mutexattr_t;
typedef int pthread_once_t;
typedef int pthread_rwlock_t;
typedef int pthread_rwlockattr_t;
# define GNULIB_defined_pthread_types 1
# endif
#endif
#ifndef PTHREAD_COND_INITIALIZER
#define PTHREAD_COND_INITIALIZER { 0 }
#define PTHREAD_MUTEX_INITIALIZER { 0 }
#define PTHREAD_ONCE_INIT { 0 }
#define PTHREAD_RWLOCK_INITIALIZER { 0 }
#define PTHREAD_BARRIER_SERIAL_THREAD (-1)
#define PTHREAD_CANCEL_DEFERRED 0
#define PTHREAD_CANCEL_ASYNCHRONOUS 1
#define PTHREAD_CANCEL_ENABLE 0
#define PTHREAD_CANCEL_DISABLE 1
#define PTHREAD_CANCELED ((void *) -1)
#define PTHREAD_CREATE_JOINABLE 0
#define PTHREAD_CREATE_DETACHED 1
#define PTHREAD_INHERIT_SCHED 0
#define PTHREAD_EXPLICIT_SCHED 1
#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
#define PTHREAD_MUTEX_NORMAL 0
#define PTHREAD_MUTEX_ERRORCHECK 1
#define PTHREAD_MUTEX_RECURSIVE 2
#define PTHREAD_MUTEX_STALLED 0
#define PTHREAD_MUTEX_ROBUST 1
#define PTHREAD_PRIO_NONE 0
#define PTHREAD_PRIO_INHERIT 1
#define PTHREAD_PRIO_PROTECT 2
#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED 1
#define PTHREAD_SCOPE_SYSTEM 0
#define PTHREAD_SCOPE_PROCESS 1
#endif
#if ! @HAVE_PTHREAD_T@
# if !GNULIB_defined_pthread_functions
/* Provide substitutes for the thread functions that should work
adequately on a single-threaded implementation, where
pthread_create always fails. The goal is to let programs compile
on non-pthread hosts with minimal runtime overhead.
Omit interfaces that have not been analyzed and for which we do not
know what to do, so that they elicit a compile-time error for
now. */
_GL_PTHREAD_INLINE int
pthread_cond_destroy (pthread_cond_t *cond)
{
/* COND is never seriously used. */
return 0;
}
_GL_PTHREAD_INLINE int
pthread_cond_init (pthread_cond_t *restrict cond,
pthread_condattr_t const *restrict attr)
{
/* COND is never seriously used. */
return 0;
}
_GL_PTHREAD_INLINE int
pthread_cond_signal (pthread_cond_t *cond)
{
/* No threads can currently be blocked on COND. */
return 0;
}
_GL_PTHREAD_INLINE int
pthread_cond_wait (pthread_cond_t *restrict cond,
pthread_mutex_t *restrict mutex)
{
/* Properly-written applications never come here. */
abort ();
return 0;
}
_GL_PTHREAD_INLINE int
pthread_create (pthread_t *restrict thread,
pthread_attr_t const *restrict attr,
void * (*start_routine) (void*), void *restrict arg)
{
/* Do not create a thread. */
return EAGAIN;
}
_GL_PTHREAD_INLINE void
pthread_exit (void *value)
{
/* There is just one thread, so the process exits. */
exit (0);
}
_GL_PTHREAD_INLINE int
pthread_join (pthread_t thread, void **pvalue)
{
/* Properly-written applications never come here. */
abort ();
return 0;
}
_GL_PTHREAD_INLINE int
pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
{
return 0;
}
_GL_PTHREAD_INLINE int
pthread_mutexattr_init (pthread_mutexattr_t *attr)
{
return 0;
}
_GL_PTHREAD_INLINE int
pthread_mutexattr_settype (pthread_mutexattr_t *attr, int attr_type)
{
return 0;
}
_GL_PTHREAD_INLINE int
pthread_mutex_destroy (pthread_mutex_t *mutex)
{
/* MUTEX is never seriously used. */
return 0;
}
_GL_PTHREAD_INLINE int
pthread_mutex_init (pthread_mutex_t *restrict mutex,
pthread_mutexattr_t const *restrict attr)
{
/* MUTEX is never seriously used. */
return 0;
}
_GL_PTHREAD_INLINE int
pthread_mutex_lock (pthread_mutex_t *mutex)
{
/* There is only one thread, so it always gets the lock. This
implementation does not support PTHREAD_MUTEX_ERRORCHECK. */
return 0;
}
_GL_PTHREAD_INLINE int
pthread_mutex_trylock (pthread_mutex_t *mutex)
{
return pthread_mutex_lock (mutex);
}
_GL_PTHREAD_INLINE int
pthread_mutex_unlock (pthread_mutex_t *mutex)
{
/* There is only one thread, so it always unlocks successfully.
This implementation does not support robust mutexes or
PTHREAD_MUTEX_ERRORCHECK. */
return 0;
}
# define GNULIB_defined_pthread_functions 1
# endif
#endif
#if ! @HAVE_PTHREAD_SPINLOCK_T@
# if !GNULIB_defined_pthread_spinlock_t
/* Approximate spinlocks with mutexes. */
typedef pthread_mutex_t pthread_spinlock_t;
_GL_PTHREAD_INLINE int
pthread_spin_init (pthread_spinlock_t *lock, int pshared)
{
return pthread_mutex_init (lock, NULL);
}
_GL_PTHREAD_INLINE int
pthread_spin_destroy (pthread_spinlock_t *lock)
{
return pthread_mutex_destroy (lock);
}
_GL_PTHREAD_INLINE int
pthread_spin_lock (pthread_spinlock_t *lock)
{
return pthread_mutex_lock (lock);
}
_GL_PTHREAD_INLINE int
pthread_spin_trylock (pthread_spinlock_t *lock)
{
return pthread_mutex_trylock (lock);
}
_GL_PTHREAD_INLINE int
pthread_spin_unlock (pthread_spinlock_t *lock)
{
return pthread_mutex_unlock (lock);
}
# define GNULIB_defined_pthread_spinlock_t 1
# endif
#endif
_GL_INLINE_HEADER_END
#endif /* _@GUARD_PREFIX@_PTHREAD_H_ */
#endif /* _@GUARD_PREFIX@_PTHREAD_H_ */
|