# HG changeset patch # User Paul Eggert # Date 1353479106 28800 # Node ID 8b10fbdb551e4f650cf5d2198d260b22ef7a8f2d # Parent 1b3c19ad4b17782e3a7b290df211ec8754500c9d pthread: better 'inline' * lib/pthread.c: New file. * lib/pthread.in.h (_GL_PTHREAD_INLINE): New macro. Replace all uses of 'static inline' with it. Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END. * m4/pthread.m4 (gl_PTHREAD_CHECK): Add AC_LIBOBJ([pthread]). Do not require AC_C_INLINE. * modules/pthread (Files): Add lib/pthread.c. (Depends-on): Add extern-inline. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2012-11-29 Paul Eggert + pthread: better 'inline' + * lib/pthread.c: New file. + * lib/pthread.in.h (_GL_PTHREAD_INLINE): + New macro. Replace all uses of 'static inline' with it. + Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END. + * m4/pthread.m4 (gl_PTHREAD_CHECK): + Add AC_LIBOBJ([pthread]). Do not require AC_C_INLINE. + * modules/pthread (Files): Add lib/pthread.c. + (Depends-on): Add extern-inline. + math: better 'inline' * lib/math.c: New file. * lib/math.in.h (_GL_MATH_INLINE): diff --git a/lib/pthread.c b/lib/pthread.c new file mode 100644 --- /dev/null +++ b/lib/pthread.c @@ -0,0 +1,3 @@ +#include +#define _GL_PTHREAD_INLINE _GL_EXTERN_INLINE +#include "pthread.h" diff --git a/lib/pthread.in.h b/lib/pthread.in.h --- a/lib/pthread.in.h +++ b/lib/pthread.in.h @@ -38,6 +38,11 @@ #include #include +_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; @@ -110,14 +115,14 @@ know what to do, so that they elicit a compile-time error for now. */ -static inline int +_GL_PTHREAD_INLINE int pthread_cond_destroy (pthread_cond_t *cond) { /* COND is never seriously used. */ return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_cond_init (pthread_cond_t *restrict cond, pthread_condattr_t const *restrict attr) { @@ -125,14 +130,14 @@ return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_cond_signal (pthread_cond_t *cond) { /* No threads can currently be blocked on COND. */ return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_cond_wait (pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex) { @@ -141,7 +146,7 @@ return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_create (pthread_t *restrict thread, pthread_attr_t const *restrict attr, void * (*start_routine) (void*), void *restrict arg) @@ -150,14 +155,14 @@ return EAGAIN; } -static inline void +_GL_PTHREAD_INLINE void pthread_exit (void *value) { /* There is just one thread, so the process exits. */ exit (0); } -static inline int +_GL_PTHREAD_INLINE int pthread_join (pthread_t thread, void **pvalue) { /* Properly-written applications never come here. */ @@ -165,32 +170,32 @@ return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_mutexattr_destroy (pthread_mutexattr_t *attr) { return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_mutexattr_init (pthread_mutexattr_t *attr) { return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int attr_type) { return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_mutex_destroy (pthread_mutex_t *mutex) { /* MUTEX is never seriously used. */ return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_mutex_init (pthread_mutex_t *restrict mutex, pthread_mutexattr_t const *restrict attr) { @@ -198,7 +203,7 @@ return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_mutex_lock (pthread_mutex_t *mutex) { /* There is only one thread, so it always gets the lock. This @@ -206,13 +211,13 @@ return 0; } -static inline int +_GL_PTHREAD_INLINE int pthread_mutex_trylock (pthread_mutex_t *mutex) { return pthread_mutex_lock (mutex); } -static inline int +_GL_PTHREAD_INLINE int pthread_mutex_unlock (pthread_mutex_t *mutex) { /* There is only one thread, so it always unlocks successfully. @@ -234,31 +239,31 @@ typedef pthread_mutex_t pthread_spinlock_t; -static inline int +_GL_PTHREAD_INLINE int pthread_spin_init (pthread_spinlock_t *lock, int pshared) { return pthread_mutex_init (lock, NULL); } -static inline int +_GL_PTHREAD_INLINE int pthread_spin_destroy (pthread_spinlock_t *lock) { return pthread_mutex_destroy (lock); } -static inline int +_GL_PTHREAD_INLINE int pthread_spin_lock (pthread_spinlock_t *lock) { return pthread_mutex_lock (lock); } -static inline int +_GL_PTHREAD_INLINE int pthread_spin_trylock (pthread_spinlock_t *lock) { return pthread_mutex_trylock (lock); } -static inline int +_GL_PTHREAD_INLINE int pthread_spin_unlock (pthread_spinlock_t *lock) { return pthread_mutex_unlock (lock); @@ -269,5 +274,7 @@ #endif +_GL_INLINE_HEADER_END + #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */ #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */ diff --git a/m4/pthread.m4 b/m4/pthread.m4 --- a/m4/pthread.m4 +++ b/m4/pthread.m4 @@ -1,4 +1,4 @@ -# pthread.m4 serial 5 +# pthread.m4 serial 7 dnl Copyright (C) 2009-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -30,6 +30,7 @@ test $ac_cv_type_pthread_t != yes || test $ac_cv_type_pthread_spinlock_t != yes; then PTHREAD_H='pthread.h' + AC_LIBOBJ([pthread]) else PTHREAD_H= fi @@ -72,7 +73,6 @@ fi AC_SUBST([LIB_PTHREAD]) - AC_REQUIRE([AC_C_INLINE]) AC_REQUIRE([AC_C_RESTRICT]) ]) diff --git a/modules/pthread b/modules/pthread --- a/modules/pthread +++ b/modules/pthread @@ -2,10 +2,12 @@ Implement a trivial subset of the pthreads library. Files: +lib/pthread.c lib/pthread.in.h m4/pthread.m4 Depends-on: +extern-inline sched time