]> Savannah Git Hosting - gnulib.git/commitdiff
pthread-thread: New module.
authorBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:37:38 +0000 (02:37 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:37:38 +0000 (02:37 +0200)
* lib/pthread.in.h (pthread_create, pthread_exit, pthread_join): Remove
inline definitions.
* lib/pthread-thread.c: New file.
* m4/pthread-thread.m4: New file.
* modules/pthread-thread: New file.
* doc/posix-functions/pthread_create.texi: Mention the new module.
* doc/posix-functions/pthread_attr_init.texi: Likewise.
* doc/posix-functions/pthread_attr_getdetachstate.texi: Likewise.
* doc/posix-functions/pthread_attr_setdetachstate.texi: Likewise.
* doc/posix-functions/pthread_attr_destroy.texi: Likewise.
* doc/posix-functions/pthread_self.texi: Likewise.
* doc/posix-functions/pthread_equal.texi: Likewise.
* doc/posix-functions/pthread_detach.texi: Likewise.
* doc/posix-functions/pthread_join.texi: Likewise.
* doc/posix-functions/pthread_exit.texi: Likewise.

15 files changed:
ChangeLog
doc/posix-functions/pthread_attr_destroy.texi
doc/posix-functions/pthread_attr_getdetachstate.texi
doc/posix-functions/pthread_attr_init.texi
doc/posix-functions/pthread_attr_setdetachstate.texi
doc/posix-functions/pthread_create.texi
doc/posix-functions/pthread_detach.texi
doc/posix-functions/pthread_equal.texi
doc/posix-functions/pthread_exit.texi
doc/posix-functions/pthread_join.texi
doc/posix-functions/pthread_self.texi
lib/pthread-thread.c [new file with mode: 0644]
lib/pthread.in.h
m4/pthread-thread.m4 [new file with mode: 0644]
modules/pthread-thread [new file with mode: 0644]

index 8e8723d74ddd5a1678c70b1d8c933159a64ab016..f21fa24175376abbe1b6fe1289144646e054c4bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2019-07-14  Bruno Haible  <bruno@clisp.org>
+
+       pthread-thread: New module.
+       * lib/pthread.in.h (pthread_create, pthread_exit, pthread_join): Remove
+       inline definitions.
+       * lib/pthread-thread.c: New file.
+       * m4/pthread-thread.m4: New file.
+       * modules/pthread-thread: New file.
+       * doc/posix-functions/pthread_create.texi: Mention the new module.
+       * doc/posix-functions/pthread_attr_init.texi: Likewise.
+       * doc/posix-functions/pthread_attr_getdetachstate.texi: Likewise.
+       * doc/posix-functions/pthread_attr_setdetachstate.texi: Likewise.
+       * doc/posix-functions/pthread_attr_destroy.texi: Likewise.
+       * doc/posix-functions/pthread_self.texi: Likewise.
+       * doc/posix-functions/pthread_equal.texi: Likewise.
+       * doc/posix-functions/pthread_detach.texi: Likewise.
+       * doc/posix-functions/pthread_join.texi: Likewise.
+       * doc/posix-functions/pthread_exit.texi: Likewise.
+
 2019-07-14  Bruno Haible  <bruno@clisp.org>
 
        pthread-h: Prepare for adding new modules.
index 2647096eeed3519cd35396f8e80493f6765fec6f..d7e776b1adf490ce9065195886aa40d814799ede 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_destroy.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
 @end itemize
index dd5862f187f400a324d12f811d24af7f2f35d326..0964f6df86c7d19d4b21f45a921fc3ebe8c2e1f0 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getdetachstate.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
 @end itemize
index 539256cc45c7a0dde9bbafb494974bcd6f3e525a..ca230fba31584e2cf12f5bba6cc1eccc4bf19d7e 100644 (file)
@@ -4,15 +4,20 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
+@item
+This function is only defined as an inline function on some platforms:
+HP-UX 11.11.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11.11, mingw, MSVC 14.
 @end itemize
index 41cb7af6b5115a18ee146c735b1d802f6e5cafbb..047e52c516c069d032c4e899a66015bedc7bfac1 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setdetachstate.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11, mingw, MSVC 14.
 @end itemize
index f9bf5bc0ea2b2743539502b844f81f288a0aa702..d17359909131e5a325ebe187d6d74b184e659fda 100644 (file)
@@ -4,20 +4,25 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
+@item
+This function is only defined as an inline function on some platforms:
+HP-UX 11.11.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
-Minix 3.1.8, HP-UX 11.11, mingw, MSVC 14.
-@item
-On Linux/glibc platforms before the advent of NPTL, signals could only be
-sent to one particular thread.  In POSIX, signals are sent to the entire
+On Linux/glibc platforms before the advent of NPTL in 2003, signals could only
+be sent to one particular thread.  In POSIX, signals are sent to the entire
 process and executed by any thread of the process that happens to have the
 particular signal currently unblocked.
 @end itemize
index ee531e92dd6774dd9d9870a1366981c161dd8070..b559d844d0bf196c3da7957048687d04eca2c300 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_detach.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
 @end itemize
index c84eeb2a9f902e85aece29a223893e7b407c6b49..479c6275c3538b13efed197bc680aea2de398927 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
 @end itemize
index 46a0851473d6f181be0c1641b81c0065767e90a0..65e66dd73513ecbfa9546d796b59fb2dc1840426 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_exit.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
 @end itemize
index 61f13f69f07cd7c9239532d10b6dfcc83d315402..6a381de593fba281d7ab54a1b54e7d33f238abfa 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
 @end itemize
index 3a04e420648961872e2a1daac1e8470ecab3e09d..5e4ab0080ceda43816c268875802438032fc6e7e 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html}
 
-Gnulib module: ---
+Gnulib module: pthread-thread
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, mingw, MSVC 14.
+But the provided replacement is just a dummy on some of these platforms:
+Minix 3.1.8.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 14.
 @end itemize
diff --git a/lib/pthread-thread.c b/lib/pthread-thread.c
new file mode 100644 (file)
index 0000000..43f1ec4
--- /dev/null
@@ -0,0 +1,178 @@
+/* Creating and controlling POSIX threads.
+   Copyright (C) 2010-2019 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
+   the Free Software Foundation; either version 2, 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Paul Eggert, 2010, and Bruno Haible <bruno@clisp.org>, 2019.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <pthread.h>
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+# include "windows-thread.h"
+#else
+# include <stdlib.h>
+#endif
+
+typedef void * (* pthread_main_function_t) (void *);
+
+#if ((defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS) || !HAVE_PTHREAD_H
+
+int
+pthread_attr_init (pthread_attr_t *attr)
+{
+  *attr = PTHREAD_CREATE_JOINABLE;
+  return 0;
+}
+
+int
+pthread_attr_getdetachstate (pthread_attr_t *attr, int *detachstatep)
+{
+  *detachstatep = *attr & (PTHREAD_CREATE_JOINABLE | PTHREAD_CREATE_DETACHED);
+  return 0;
+}
+
+int
+pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
+{
+  if (!(detachstate == PTHREAD_CREATE_JOINABLE
+        || detachstate == PTHREAD_CREATE_DETACHED))
+    return EINVAL;
+  *attr ^= (*attr ^ detachstate)
+           & (PTHREAD_CREATE_JOINABLE | PTHREAD_CREATE_DETACHED);
+  return 0;
+}
+
+int
+pthread_attr_destroy (pthread_attr_t *attr _GL_UNUSED)
+{
+  return 0;
+}
+
+#endif
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+/* Use Windows threads.  */
+
+int
+pthread_create (pthread_t *threadp, const pthread_attr_t *attr,
+                pthread_main_function_t mainfunc, void *arg)
+{
+  unsigned int glwthread_attr =
+    (attr != NULL
+     && (*attr & (PTHREAD_CREATE_JOINABLE | PTHREAD_CREATE_DETACHED))
+        != PTHREAD_CREATE_JOINABLE
+     ? GLWTHREAD_ATTR_DETACHED
+     : 0);
+  return glwthread_thread_create (threadp, glwthread_attr, mainfunc, arg);
+}
+
+pthread_t
+pthread_self (void)
+{
+  return glwthread_thread_self ();
+}
+
+int
+pthread_equal (pthread_t thread1, pthread_t thread2)
+{
+  return thread1 == thread2;
+}
+
+int
+pthread_detach (pthread_t thread)
+{
+  return glwthread_thread_detach (thread);
+}
+
+int
+pthread_join (pthread_t thread, void **valuep)
+{
+  return glwthread_thread_join (thread, valuep);
+}
+
+void
+pthread_exit (void *value)
+{
+  glwthread_thread_exit (value);
+}
+
+#elif HAVE_PTHREAD_H
+/* Provide workarounds for POSIX threads.  */
+
+# if PTHREAD_CREATE_IS_INLINE
+int
+pthread_create (pthread_t *threadp, const pthread_attr_t *attr,
+                pthread_main_function_t mainfunc, void *arg)
+#  undef pthread_create
+{
+  return pthread_create (threadp, attr, mainfunc, arg);
+}
+
+int
+pthread_attr_init (pthread_attr_t *attr)
+#  undef pthread_attr_init
+{
+  return pthread_attr_init (attr);
+}
+
+# endif
+
+#else
+/* Provide a dummy implementation for single-threaded applications.  */
+
+int
+pthread_create (pthread_t *threadp, const pthread_attr_t *attr,
+                pthread_main_function_t mainfunc, void *arg)
+{
+  /* The maximum number of threads is reached.  Do not create a thread.  */
+  return EAGAIN;
+}
+
+pthread_t
+pthread_self (void)
+{
+  return 42;
+}
+
+int
+pthread_equal (pthread_t thread1, pthread_t thread2)
+{
+  return thread1 == thread2;
+}
+
+int
+pthread_detach (pthread_t thread)
+{
+  /* There are no joinable threads.  */
+  return EINVAL;
+}
+
+int
+pthread_join (pthread_t thread, void **valuep)
+{
+  /* There are no joinable threads.  */
+  return EINVAL;
+}
+
+void
+pthread_exit (void *value)
+{
+  /* There is just one thread, so the process exits.  */
+  exit (0);
+}
+
+#endif
index 83b56ad6d2f7633adff401b993562d2ee2b6207b..88f349d4e504c137c966a0ab3acd0c663d46c0b7 100644 (file)
@@ -408,30 +408,6 @@ pthread_cond_wait (pthread_cond_t *restrict cond,
   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)
 {
diff --git a/m4/pthread-thread.m4 b/m4/pthread-thread.m4
new file mode 100644 (file)
index 0000000..eef29c9
--- /dev/null
@@ -0,0 +1,69 @@
+# pthread-thread.m4 serial 1
+dnl Copyright (C) 2019 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_PTHREAD_THREAD],
+[
+  AC_REQUIRE([gl_PTHREAD_H])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+
+  if { case "$host_os" in mingw*) true;; *) false;; esac; } \
+     && test $gl_threads_api = windows; then
+    dnl Choose function names that don't conflict with the mingw-w64 winpthreads
+    dnl library.
+    REPLACE_PTHREAD_CREATE=1
+    REPLACE_PTHREAD_ATTR_INIT=1
+    REPLACE_PTHREAD_ATTR_GETDETACHSTATE=1
+    REPLACE_PTHREAD_ATTR_SETDETACHSTATE=1
+    REPLACE_PTHREAD_ATTR_DESTROY=1
+    REPLACE_PTHREAD_SELF=1
+    REPLACE_PTHREAD_EQUAL=1
+    REPLACE_PTHREAD_DETACH=1
+    REPLACE_PTHREAD_JOIN=1
+    REPLACE_PTHREAD_EXIT=1
+  else
+    if test $HAVE_PTHREAD_H = 0; then
+      HAVE_PTHREAD_CREATE=0
+      HAVE_PTHREAD_ATTR_INIT=0
+      HAVE_PTHREAD_ATTR_GETDETACHSTATE=0
+      HAVE_PTHREAD_ATTR_SETDETACHSTATE=0
+      HAVE_PTHREAD_ATTR_DESTROY=0
+      HAVE_PTHREAD_SELF=0
+      HAVE_PTHREAD_EQUAL=0
+      HAVE_PTHREAD_DETACH=0
+      HAVE_PTHREAD_JOIN=0
+      HAVE_PTHREAD_EXIT=0
+    else
+      dnl On HP-UX 11.11, pthread_create() and pthread_attr_init() are only
+      dnl defined as inline functions.
+      AC_CACHE_CHECK([whether pthread_create exists as a global function],
+        [gl_cv_func_pthread_create],
+        [saved_LIBS="$LIBS"
+         LIBS="$LIBS $LIBMULTITHREAD"
+         AC_LINK_IFELSE(
+           [AC_LANG_SOURCE(
+              [[extern
+                #ifdef __cplusplus
+                "C"
+                #endif
+                int pthread_create (void);
+                int main ()
+                {
+                  return pthread_create ();
+                }
+              ]])],
+           [gl_cv_func_pthread_create=yes],
+           [gl_cv_func_pthread_create=no])
+         LIBS="$saved_LIBS"
+        ])
+      if test $gl_cv_func_pthread_create = no; then
+        REPLACE_PTHREAD_CREATE=1
+        REPLACE_PTHREAD_ATTR_INIT=1
+        AC_DEFINE([PTHREAD_CREATE_IS_INLINE], [1],
+          [Define if pthread_create is an inline function.])
+      fi
+    fi
+  fi
+])
diff --git a/modules/pthread-thread b/modules/pthread-thread
new file mode 100644 (file)
index 0000000..b9133d8
--- /dev/null
@@ -0,0 +1,31 @@
+Description:
+Creating and controlling POSIX threads.
+
+Files:
+lib/pthread-thread.c
+m4/pthread-thread.m4
+
+Depends-on:
+pthread-h
+windows-thread  [test $gl_threads_api = windows]
+
+configure.ac:
+gl_PTHREAD_THREAD
+if test $HAVE_PTHREAD_CREATE = 0 || test $REPLACE_PTHREAD_CREATE = 1; then
+  AC_LIBOBJ([pthread-thread])
+fi
+gl_PTHREAD_MODULE_INDICATOR([pthread-thread])
+
+Makefile.am:
+
+Include:
+<pthread.h>
+
+Link:
+$(LIBMULTITHREAD)
+
+License:
+LGPLv2+
+
+Maintainer:
+all