summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog19
-rw-r--r--doc/posix-functions/pthread_attr_destroy.texi10
-rw-r--r--doc/posix-functions/pthread_attr_getdetachstate.texi10
-rw-r--r--doc/posix-functions/pthread_attr_init.texi13
-rw-r--r--doc/posix-functions/pthread_attr_setdetachstate.texi10
-rw-r--r--doc/posix-functions/pthread_create.texi17
-rw-r--r--doc/posix-functions/pthread_detach.texi10
-rw-r--r--doc/posix-functions/pthread_equal.texi10
-rw-r--r--doc/posix-functions/pthread_exit.texi10
-rw-r--r--doc/posix-functions/pthread_join.texi10
-rw-r--r--doc/posix-functions/pthread_self.texi10
-rw-r--r--lib/pthread-thread.c178
-rw-r--r--lib/pthread.in.h24
-rw-r--r--m4/pthread-thread.m469
-rw-r--r--modules/pthread-thread31
15 files changed, 365 insertions, 66 deletions
diff --git a/ChangeLog b/ChangeLog
index 8e8723d74d..f21fa24175 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
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.
* lib/pthread.in.h: Define the types and macros for each of the
facilities separately.
diff --git a/doc/posix-functions/pthread_attr_destroy.texi b/doc/posix-functions/pthread_attr_destroy.texi
index 2647096eee..d7e776b1ad 100644
--- a/doc/posix-functions/pthread_attr_destroy.texi
+++ b/doc/posix-functions/pthread_attr_destroy.texi
@@ -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
diff --git a/doc/posix-functions/pthread_attr_getdetachstate.texi b/doc/posix-functions/pthread_attr_getdetachstate.texi
index dd5862f187..0964f6df86 100644
--- a/doc/posix-functions/pthread_attr_getdetachstate.texi
+++ b/doc/posix-functions/pthread_attr_getdetachstate.texi
@@ -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
diff --git a/doc/posix-functions/pthread_attr_init.texi b/doc/posix-functions/pthread_attr_init.texi
index 539256cc45..ca230fba31 100644
--- a/doc/posix-functions/pthread_attr_init.texi
+++ b/doc/posix-functions/pthread_attr_init.texi
@@ -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
diff --git a/doc/posix-functions/pthread_attr_setdetachstate.texi b/doc/posix-functions/pthread_attr_setdetachstate.texi
index 41cb7af6b5..047e52c516 100644
--- a/doc/posix-functions/pthread_attr_setdetachstate.texi
+++ b/doc/posix-functions/pthread_attr_setdetachstate.texi
@@ -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
diff --git a/doc/posix-functions/pthread_create.texi b/doc/posix-functions/pthread_create.texi
index f9bf5bc0ea..d173599091 100644
--- a/doc/posix-functions/pthread_create.texi
+++ b/doc/posix-functions/pthread_create.texi
@@ -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
diff --git a/doc/posix-functions/pthread_detach.texi b/doc/posix-functions/pthread_detach.texi
index ee531e92dd..b559d844d0 100644
--- a/doc/posix-functions/pthread_detach.texi
+++ b/doc/posix-functions/pthread_detach.texi
@@ -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
diff --git a/doc/posix-functions/pthread_equal.texi b/doc/posix-functions/pthread_equal.texi
index c84eeb2a9f..479c6275c3 100644
--- a/doc/posix-functions/pthread_equal.texi
+++ b/doc/posix-functions/pthread_equal.texi
@@ -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
diff --git a/doc/posix-functions/pthread_exit.texi b/doc/posix-functions/pthread_exit.texi
index 46a0851473..65e66dd735 100644
--- a/doc/posix-functions/pthread_exit.texi
+++ b/doc/posix-functions/pthread_exit.texi
@@ -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
diff --git a/doc/posix-functions/pthread_join.texi b/doc/posix-functions/pthread_join.texi
index 61f13f69f0..6a381de593 100644
--- a/doc/posix-functions/pthread_join.texi
+++ b/doc/posix-functions/pthread_join.texi
@@ -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
diff --git a/doc/posix-functions/pthread_self.texi b/doc/posix-functions/pthread_self.texi
index 3a04e42064..5e4ab0080c 100644
--- a/doc/posix-functions/pthread_self.texi
+++ b/doc/posix-functions/pthread_self.texi
@@ -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
index 0000000000..43f1ec4bbc
--- /dev/null
+++ b/lib/pthread-thread.c
@@ -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
diff --git a/lib/pthread.in.h b/lib/pthread.in.h
index 83b56ad6d2..88f349d4e5 100644
--- a/lib/pthread.in.h
+++ b/lib/pthread.in.h
@@ -409,30 +409,6 @@ pthread_cond_wait (pthread_cond_t *restrict cond,
}
_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)
{
return 0;
diff --git a/m4/pthread-thread.m4 b/m4/pthread-thread.m4
new file mode 100644
index 0000000000..eef29c9933
--- /dev/null
+++ b/m4/pthread-thread.m4
@@ -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
index 0000000000..b9133d82e1
--- /dev/null
+++ b/modules/pthread-thread
@@ -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