X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fpthread.in.h;h=da7bd4eebfed4f062abe791349d6f6c7432ccc9e;hb=03f358b413de011c710f08b85cdeb0e5b10a3731;hp=bb201a27c9bf8275064e901c25e595499f19d1c6;hpb=7f2ece896984db0787f92ce2d95462d41eef442f;p=gnulib.git diff --git a/lib/pthread.in.h b/lib/pthread.in.h index bb201a27c..da7bd4eeb 100644 --- a/lib/pthread.in.h +++ b/lib/pthread.in.h @@ -1,6 +1,6 @@ /* 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 @@ -19,6 +19,18 @@ /* Written by Paul Eggert and Glen Lenker. */ #ifndef _GL_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 _GL_PTHREAD_H_ #define _GL_PTHREAD_H_ #include @@ -27,7 +39,8 @@ #include #include -#ifndef HAVE_PTHREAD_T +#if ! @HAVE_PTHREAD_T@ +# if !GNULIB_defined_pthread_types typedef int pthread_t; typedef int pthread_attr_t; typedef int pthread_barrier_t; @@ -40,9 +53,11 @@ typedef int pthread_once_t; typedef int pthread_rwlock_t; typedef int pthread_rwlockattr_t; - typedef int pthread_spinlock_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 } @@ -81,6 +96,11 @@ #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 @@ -100,7 +120,7 @@ pthread_cond_destroy (pthread_cond_t *cond) static inline int pthread_cond_init (pthread_cond_t *restrict cond, - pthread_condattr_t const *restrict attr) + pthread_condattr_t const *restrict attr) { /* COND is never seriously used. */ return 0; @@ -115,7 +135,7 @@ pthread_cond_signal (pthread_cond_t *cond) static inline int pthread_cond_wait (pthread_cond_t *restrict cond, - pthread_mutex_t *restrict mutex) + pthread_mutex_t *restrict mutex) { /* Properly-written applications never come here. */ abort (); @@ -147,6 +167,24 @@ pthread_join (pthread_t thread, void **pvalue) } static inline int +pthread_mutexattr_destroy (pthread_mutexattr_t *attr) +{ + return 0; +} + +static inline int +pthread_mutexattr_init (pthread_mutexattr_t *attr) +{ + return 0; +} + +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. */ @@ -155,7 +193,7 @@ pthread_mutex_destroy (pthread_mutex_t *mutex) static inline int pthread_mutex_init (pthread_mutex_t *restrict mutex, - pthread_mutexattr_t const *restrict attr) + pthread_mutexattr_t const *restrict attr) { /* MUTEX is never seriously used. */ return 0; @@ -170,6 +208,12 @@ pthread_mutex_lock (pthread_mutex_t *mutex) } 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. @@ -178,33 +222,53 @@ pthread_mutex_unlock (pthread_mutex_t *mutex) 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) { - /* LOCK is never seriously used. */ - return 0; + 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) { - /* Only one thread, so it always gets the lock. */ - return 0; + return pthread_mutex_lock (lock); } static inline int pthread_spin_trylock (pthread_spinlock_t *lock) { - /* Only one thread, so it always gets the lock. Assume that a - thread never tries a lock that it already holds. */ - return 0; + return pthread_mutex_trylock (lock); } static inline int pthread_spin_unlock (pthread_spinlock_t *lock) { - /* Only one thread, so spin locks are no-ops. */ - return 0; + return pthread_mutex_unlock (lock); } +# define GNULIB_defined_pthread_spinlock_t 1 +# endif + +#endif + +#endif /* _GL_PTHREAD_H_ */ #endif /* _GL_PTHREAD_H_ */