X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fpthread.in.h;h=c05c7c9f5969857594c962d6fc8ce65956e8c2ae;hb=6815bc73969d38c2226cf6e3366c1e4f4f756ba0;hp=89fbc03726203c5c0bc58092c4d67a7160601958;hpb=b2e2010c7c902235b5efb5bd3c6529f61b093aa4;p=gnulib.git diff --git a/lib/pthread.in.h b/lib/pthread.in.h index 89fbc0372..c05c7c9f5 100644 --- a/lib/pthread.in.h +++ b/lib/pthread.in.h @@ -1,6 +1,6 @@ -/* Implement a trivial subset of the pthreads library. +/* Implement a trivial subset of POSIX 1003.1-2008 pthread.h. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2009-2011 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,31 +16,259 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* Written by Glen Lenker. */ +/* Written by Paul Eggert and Glen Lenker. */ -#ifndef PTHREAD_H_ -# define PTHREAD_H_ +#ifndef _@GUARD_PREFIX@_PTHREAD_H_ -# include -# include +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ -typedef int pthread_t; -typedef int pthread_attr_t; +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_PTHREAD_H@ +# @INCLUDE_NEXT@ @NEXT_PTHREAD_H@ +#endif -static int +#ifndef _@GUARD_PREFIX@_PTHREAD_H_ +#define _@GUARD_PREFIX@_PTHREAD_H_ + +#include +#include +#include +#include +#include + +#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. */ + +static inline int +pthread_cond_destroy (pthread_cond_t *cond) +{ + /* COND is never seriously used. */ + return 0; +} + +static inline int +pthread_cond_init (pthread_cond_t *restrict cond, + pthread_condattr_t const *restrict attr) +{ + /* COND is never seriously used. */ + return 0; +} + +static inline int +pthread_cond_signal (pthread_cond_t *cond) +{ + /* No threads can currently be blocked on COND. */ + return 0; +} + +static inline int +pthread_cond_wait (pthread_cond_t *restrict cond, + pthread_mutex_t *restrict mutex) +{ + /* Properly-written applications never come here. */ + abort (); + return 0; +} + +static inline int pthread_create (pthread_t *restrict thread, - const pthread_attr_t *restrict attr, - void *(*start_routine)(void*), void *restrict arg) + pthread_attr_t const *restrict attr, + void * (*start_routine) (void*), void *restrict arg) { - errno = EAGAIN; - return -1; + /* Do not create a thread. */ + return EAGAIN; } -static int -pthread_join (pthread_t thread, void **value_ptr) +static inline void +pthread_exit (void *value) { + /* There is just one thread, so the process exits. */ + exit (0); +} + +static inline int +pthread_join (pthread_t thread, void **pvalue) +{ + /* Properly-written applications never come here. */ abort (); - return -1; + return 0; +} + +static inline int +pthread_mutexattr_destroy (pthread_mutexattr_t *attr) +{ + return 0; +} + +static inline int +pthread_mutexattr_init (pthread_mutexattr_t *attr) +{ + return 0; } -#endif /* PTHREAD_H_ */ +static inline int +pthread_mutexattr_settype (pthread_mutexattr_t *attr, int attr_type) +{ + return 0; +} + +static inline int +pthread_mutex_destroy (pthread_mutex_t *mutex) +{ + /* MUTEX is never seriously used. */ + return 0; +} + +static inline int +pthread_mutex_init (pthread_mutex_t *restrict mutex, + pthread_mutexattr_t const *restrict attr) +{ + /* MUTEX is never seriously used. */ + return 0; +} + +static 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; +} + +static inline int +pthread_mutex_trylock (pthread_mutex_t *mutex) +{ + return pthread_mutex_lock (mutex); +} + +static 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; + +static inline int +pthread_spin_init (pthread_spinlock_t *lock, int pshared) +{ + return pthread_mutex_init (lock, NULL); +} + +static inline int +pthread_spin_destroy (pthread_spinlock_t *lock) +{ + return pthread_mutex_destroy (lock); +} + +static inline int +pthread_spin_lock (pthread_spinlock_t *lock) +{ + return pthread_mutex_lock (lock); +} + +static inline int +pthread_spin_trylock (pthread_spinlock_t *lock) +{ + return pthread_mutex_trylock (lock); +} + +static inline int +pthread_spin_unlock (pthread_spinlock_t *lock) +{ + return pthread_mutex_unlock (lock); +} + +# define GNULIB_defined_pthread_spinlock_t 1 +# endif + +#endif + +#endif /* _@GUARD_PREFIX@_PTHREAD_H_ */ +#endif /* _@GUARD_PREFIX@_PTHREAD_H_ */