changeset 17169:8b10fbdb551e

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.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 20 Nov 2012 22:25:06 -0800
parents 1b3c19ad4b17
children 661d79eb6d77
files ChangeLog lib/pthread.c lib/pthread.in.h m4/pthread.m4 modules/pthread
diffstat 5 files changed, 44 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2012-11-29  Paul Eggert  <eggert@cs.ucla.edu>
 
+	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):
new file mode 100644
--- /dev/null
+++ b/lib/pthread.c
@@ -0,0 +1,3 @@
+#include <config.h>
+#define _GL_PTHREAD_INLINE _GL_EXTERN_INLINE
+#include "pthread.h"
--- a/lib/pthread.in.h
+++ b/lib/pthread.in.h
@@ -38,6 +38,11 @@
 #include <sys/types.h>
 #include <time.h>
 
+_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_ */
--- 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])
 ])
 
--- 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