From e09ceafdb38f57a50bc88e820c8af1d95b7aae22 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 15 Jul 2019 02:37:44 +0200 Subject: [PATCH] pthread-mutex: New module. * lib/pthread.in.h (pthread_mutexattr_destroy, pthread_mutexattr_init, pthread_mutexattr_settype, pthread_mutex_destroy, pthread_mutex_init, pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_timedlock, pthread_mutex_unlock): Remove inline definitions. * lib/pthread-mutex.c: New file. * m4/pthread-mutex.m4: New file. * modules/pthread-mutex: New file. * doc/posix-functions/pthread_mutex_init.texi: Mention the new module. * doc/posix-functions/pthread_mutexattr_init.texi: Likewise. * doc/posix-functions/pthread_mutexattr_gettype.texi: Likewise. * doc/posix-functions/pthread_mutexattr_settype.texi: Likewise. * doc/posix-functions/pthread_mutexattr_getrobust.texi: Likewise. * doc/posix-functions/pthread_mutexattr_setrobust.texi: Likewise. * doc/posix-functions/pthread_mutexattr_destroy.texi: Likewise. * doc/posix-functions/pthread_mutex_lock.texi: Likewise. * doc/posix-functions/pthread_mutex_trylock.texi: Likewise. * doc/posix-functions/pthread_mutex_timedlock.texi: Likewise. * doc/posix-functions/pthread_mutex_unlock.texi: Likewise. * doc/posix-functions/pthread_mutex_destroy.texi: Likewise. --- ChangeLog | 23 ++ .../pthread_mutex_destroy.texi | 10 +- doc/posix-functions/pthread_mutex_init.texi | 10 +- doc/posix-functions/pthread_mutex_lock.texi | 10 +- .../pthread_mutex_timedlock.texi | 2 +- .../pthread_mutex_trylock.texi | 10 +- doc/posix-functions/pthread_mutex_unlock.texi | 10 +- .../pthread_mutexattr_destroy.texi | 10 +- .../pthread_mutexattr_getrobust.texi | 9 +- .../pthread_mutexattr_gettype.texi | 10 +- .../pthread_mutexattr_init.texi | 10 +- .../pthread_mutexattr_setrobust.texi | 9 +- .../pthread_mutexattr_settype.texi | 10 +- lib/pthread-mutex.c | 239 ++++++++++++++++++ lib/pthread.in.h | 64 ----- m4/pthread-mutex.m4 | 44 ++++ modules/pthread-mutex | 33 +++ 17 files changed, 404 insertions(+), 109 deletions(-) create mode 100644 lib/pthread-mutex.c create mode 100644 m4/pthread-mutex.m4 create mode 100644 modules/pthread-mutex diff --git a/ChangeLog b/ChangeLog index b23cffa191..7f778a9f47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2019-07-14 Bruno Haible + + pthread-mutex: New module. + * lib/pthread.in.h (pthread_mutexattr_destroy, pthread_mutexattr_init, + pthread_mutexattr_settype, pthread_mutex_destroy, pthread_mutex_init, + pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_timedlock, + pthread_mutex_unlock): Remove inline definitions. + * lib/pthread-mutex.c: New file. + * m4/pthread-mutex.m4: New file. + * modules/pthread-mutex: New file. + * doc/posix-functions/pthread_mutex_init.texi: Mention the new module. + * doc/posix-functions/pthread_mutexattr_init.texi: Likewise. + * doc/posix-functions/pthread_mutexattr_gettype.texi: Likewise. + * doc/posix-functions/pthread_mutexattr_settype.texi: Likewise. + * doc/posix-functions/pthread_mutexattr_getrobust.texi: Likewise. + * doc/posix-functions/pthread_mutexattr_setrobust.texi: Likewise. + * doc/posix-functions/pthread_mutexattr_destroy.texi: Likewise. + * doc/posix-functions/pthread_mutex_lock.texi: Likewise. + * doc/posix-functions/pthread_mutex_trylock.texi: Likewise. + * doc/posix-functions/pthread_mutex_timedlock.texi: Likewise. + * doc/posix-functions/pthread_mutex_unlock.texi: Likewise. + * doc/posix-functions/pthread_mutex_destroy.texi: Likewise. + 2019-07-14 Bruno Haible pthread-once: New module. diff --git a/doc/posix-functions/pthread_mutex_destroy.texi b/doc/posix-functions/pthread_mutex_destroy.texi index ce8760af98..c5a081d2ad 100644 --- a/doc/posix-functions/pthread_mutex_destroy.texi +++ b/doc/posix-functions/pthread_mutex_destroy.texi @@ -4,15 +4,17 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html} -Gnulib module: --- +Gnulib module: pthread-mutex 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_mutex_init.texi b/doc/posix-functions/pthread_mutex_init.texi index 3250347320..fb86ed2f02 100644 --- a/doc/posix-functions/pthread_mutex_init.texi +++ b/doc/posix-functions/pthread_mutex_init.texi @@ -4,15 +4,17 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html} -Gnulib module: --- +Gnulib module: pthread-mutex 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_mutex_lock.texi b/doc/posix-functions/pthread_mutex_lock.texi index 1ee849aa70..2946aa964a 100644 --- a/doc/posix-functions/pthread_mutex_lock.texi +++ b/doc/posix-functions/pthread_mutex_lock.texi @@ -4,15 +4,17 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html} -Gnulib module: --- +Gnulib module: pthread-mutex 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_mutex_timedlock.texi b/doc/posix-functions/pthread_mutex_timedlock.texi index 7fa3745ad2..aac3a4ce9a 100644 --- a/doc/posix-functions/pthread_mutex_timedlock.texi +++ b/doc/posix-functions/pthread_mutex_timedlock.texi @@ -12,7 +12,7 @@ Portability problems fixed by Gnulib: This function is missing on some platforms: Mac OS X 10.5, FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, mingw, MSVC 14, Android 4.4. But the provided replacement is just a dummy on some of these platforms: -Minix 3.1.8, HP-UX 11, mingw, MSVC 14. +Minix 3.1.8. @end itemize Portability problems not fixed by Gnulib: diff --git a/doc/posix-functions/pthread_mutex_trylock.texi b/doc/posix-functions/pthread_mutex_trylock.texi index 8da95774b5..84f3e0fba7 100644 --- a/doc/posix-functions/pthread_mutex_trylock.texi +++ b/doc/posix-functions/pthread_mutex_trylock.texi @@ -4,15 +4,17 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_trylock.html} -Gnulib module: --- +Gnulib module: pthread-mutex 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_mutex_unlock.texi b/doc/posix-functions/pthread_mutex_unlock.texi index 608bb13322..785254e67f 100644 --- a/doc/posix-functions/pthread_mutex_unlock.texi +++ b/doc/posix-functions/pthread_mutex_unlock.texi @@ -4,15 +4,17 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_unlock.html} -Gnulib module: --- +Gnulib module: pthread-mutex 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_mutexattr_destroy.texi b/doc/posix-functions/pthread_mutexattr_destroy.texi index bf643e4ef4..ed9f85e59d 100644 --- a/doc/posix-functions/pthread_mutexattr_destroy.texi +++ b/doc/posix-functions/pthread_mutexattr_destroy.texi @@ -4,15 +4,17 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_destroy.html} -Gnulib module: --- +Gnulib module: pthread-mutex 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_mutexattr_getrobust.texi b/doc/posix-functions/pthread_mutexattr_getrobust.texi index fe4cfdc937..285e5772db 100644 --- a/doc/posix-functions/pthread_mutexattr_getrobust.texi +++ b/doc/posix-functions/pthread_mutexattr_getrobust.texi @@ -4,15 +4,16 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getrobust.html} -Gnulib module: --- +Gnulib module: pthread-mutex Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +glibc 2.11, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, Cygwin, mingw, MSVC 14, Android 9.0. +But the provided replacement is just a dummy. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -glibc 2.11, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, Cygwin, mingw, MSVC 14, Android 9.0. @end itemize diff --git a/doc/posix-functions/pthread_mutexattr_gettype.texi b/doc/posix-functions/pthread_mutexattr_gettype.texi index f790f6e5bd..8d38770661 100644 --- a/doc/posix-functions/pthread_mutexattr_gettype.texi +++ b/doc/posix-functions/pthread_mutexattr_gettype.texi @@ -4,15 +4,17 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html} -Gnulib module: --- +Gnulib module: pthread-mutex 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_mutexattr_init.texi b/doc/posix-functions/pthread_mutexattr_init.texi index 33ecf9fed8..e631d8c454 100644 --- a/doc/posix-functions/pthread_mutexattr_init.texi +++ b/doc/posix-functions/pthread_mutexattr_init.texi @@ -4,15 +4,17 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_init.html} -Gnulib module: --- +Gnulib module: pthread-mutex 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_mutexattr_setrobust.texi b/doc/posix-functions/pthread_mutexattr_setrobust.texi index 31f0ff7aa5..b9e5dbc721 100644 --- a/doc/posix-functions/pthread_mutexattr_setrobust.texi +++ b/doc/posix-functions/pthread_mutexattr_setrobust.texi @@ -4,15 +4,16 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_setrobust.html} -Gnulib module: --- +Gnulib module: pthread-mutex Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +glibc 2.11, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, Cygwin, mingw, MSVC 14, Android 9.0. +But the provided replacement is just a dummy. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -glibc 2.11, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, Cygwin, mingw, MSVC 14, Android 9.0. @end itemize diff --git a/doc/posix-functions/pthread_mutexattr_settype.texi b/doc/posix-functions/pthread_mutexattr_settype.texi index 4ffcbe9842..82c6699d91 100644 --- a/doc/posix-functions/pthread_mutexattr_settype.texi +++ b/doc/posix-functions/pthread_mutexattr_settype.texi @@ -4,15 +4,17 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_settype.html} -Gnulib module: --- +Gnulib module: pthread-mutex 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/lib/pthread-mutex.c b/lib/pthread-mutex.c new file mode 100644 index 0000000000..7a6fc1a722 --- /dev/null +++ b/lib/pthread-mutex.c @@ -0,0 +1,239 @@ +/* POSIX mutexes (locks). + 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 . */ + +/* Written by Paul Eggert, 2010, and Bruno Haible , 2019. */ + +#include + +/* Specification. */ +#include + +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +# include "windows-timedmutex.h" +# include "windows-timedrecmutex.h" +#else +# include +#endif + +#if ((defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS) || !HAVE_PTHREAD_H + +int +pthread_mutexattr_init (pthread_mutexattr_t *attr) +{ + *attr = (PTHREAD_MUTEX_STALLED << 2) | PTHREAD_MUTEX_DEFAULT; + return 0; +} + +int +pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *typep) +{ + *typep = *attr & (PTHREAD_MUTEX_DEFAULT | PTHREAD_MUTEX_NORMAL + | PTHREAD_MUTEX_ERRORCHECK | PTHREAD_MUTEX_RECURSIVE); + return 0; +} + +int +pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type) +{ + if (!(type == PTHREAD_MUTEX_DEFAULT + || type == PTHREAD_MUTEX_NORMAL + || type == PTHREAD_MUTEX_ERRORCHECK + || type == PTHREAD_MUTEX_RECURSIVE)) + return EINVAL; + *attr ^= (*attr ^ type) + & (PTHREAD_MUTEX_DEFAULT | PTHREAD_MUTEX_NORMAL + | PTHREAD_MUTEX_ERRORCHECK | PTHREAD_MUTEX_RECURSIVE); + return 0; +} + +int +pthread_mutexattr_getrobust (const pthread_mutexattr_t *attr, int *robustp) +{ + *robustp = (*attr >> 2) & (PTHREAD_MUTEX_STALLED | PTHREAD_MUTEX_ROBUST); + return 0; +} + +int +pthread_mutexattr_setrobust (pthread_mutexattr_t *attr, int robust) +{ + if (!(robust == PTHREAD_MUTEX_STALLED || robust == PTHREAD_MUTEX_ROBUST)) + return EINVAL; + *attr ^= (*attr ^ (robust << 2)) + & ((PTHREAD_MUTEX_STALLED | PTHREAD_MUTEX_ROBUST) << 2); + return 0; +} + +int +pthread_mutexattr_destroy (pthread_mutexattr_t *attr _GL_UNUSED) +{ + return 0; +} + +#endif + +#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS +/* Use Windows threads. */ + +int +pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) +{ + /* This implementation does not support PTHREAD_MUTEX_ERRORCHECK + and ignores the 'robust' attribute. */ + if (attr != NULL + && (*attr & (PTHREAD_MUTEX_DEFAULT | PTHREAD_MUTEX_NORMAL + | PTHREAD_MUTEX_ERRORCHECK | PTHREAD_MUTEX_RECURSIVE)) + == PTHREAD_MUTEX_RECURSIVE) + { + mutex->type = 2; + return glwthread_timedrecmutex_init (&mutex->u.u_timedrecmutex); + } + else + { + mutex->type = 1; + return glwthread_timedmutex_init (&mutex->u.u_timedmutex); + } +} + +int +pthread_mutex_lock (pthread_mutex_t *mutex) +{ + switch (mutex->type) + { + case 1: + return glwthread_timedmutex_lock (&mutex->u.u_timedmutex); + case 2: + return glwthread_timedrecmutex_lock (&mutex->u.u_timedrecmutex); + default: + abort (); + } +} + +int +pthread_mutex_trylock (pthread_mutex_t *mutex) +{ + switch (mutex->type) + { + case 1: + return glwthread_timedmutex_trylock (&mutex->u.u_timedmutex); + case 2: + return glwthread_timedrecmutex_trylock (&mutex->u.u_timedrecmutex); + default: + abort (); + } +} + +int +pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime) +{ + switch (mutex->type) + { + case 1: + return glwthread_timedmutex_timedlock (&mutex->u.u_timedmutex, abstime); + case 2: + return glwthread_timedrecmutex_timedlock (&mutex->u.u_timedrecmutex, + abstime); + default: + abort (); + } +} + +int +pthread_mutex_unlock (pthread_mutex_t *mutex) +{ + switch (mutex->type) + { + case 1: + return glwthread_timedmutex_unlock (&mutex->u.u_timedmutex); + case 2: + return glwthread_timedrecmutex_unlock (&mutex->u.u_timedrecmutex); + default: + abort (); + } +} + +int +pthread_mutex_destroy (pthread_mutex_t *mutex) +{ + switch (mutex->type) + { + case 1: + return glwthread_timedmutex_destroy (&mutex->u.u_timedmutex); + case 2: + return glwthread_timedrecmutex_destroy (&mutex->u.u_timedrecmutex); + default: + abort (); + } +} + +#elif HAVE_PTHREAD_H +/* Provide workarounds for POSIX threads. */ + +/* pthread_mutex_timedlock is defined by the 'pthread_mutex_timedlock' + module. */ + +#else +/* Provide a dummy implementation for single-threaded applications. */ + +int +pthread_mutex_init (pthread_mutex_t *mutex _GL_UNUSED, + const pthread_mutexattr_t *attr _GL_UNUSED) +{ + /* MUTEX is never seriously used. */ + return 0; +} + +int +pthread_mutex_lock (pthread_mutex_t *mutex _GL_UNUSED) +{ + /* There is only one thread, so it always gets the lock. This + implementation does not support PTHREAD_MUTEX_ERRORCHECK. */ + return 0; +} + +int +pthread_mutex_trylock (pthread_mutex_t *mutex _GL_UNUSED) +{ + /* There is only one thread, so it always gets the lock. This + implementation does not support PTHREAD_MUTEX_ERRORCHECK. */ + return 0; +} + +int +pthread_mutex_timedlock (pthread_mutex_t *mutex _GL_UNUSED, + const struct timespec *abstime _GL_UNUSED) +{ + /* There is only one thread, so it always gets the lock. This + implementation does not support PTHREAD_MUTEX_ERRORCHECK. */ + return 0; +} + +int +pthread_mutex_unlock (pthread_mutex_t *mutex _GL_UNUSED) +{ + /* There is only one thread, so it always unlocks successfully. + This implementation does not support robust mutexes or + PTHREAD_MUTEX_ERRORCHECK. */ + return 0; +} + +int +pthread_mutex_destroy (pthread_mutex_t *mutex _GL_UNUSED) +{ + /* MUTEX is never seriously used. */ + return 0; +} + +#endif diff --git a/lib/pthread.in.h b/lib/pthread.in.h index 88f349d4e5..b3e6b596aa 100644 --- a/lib/pthread.in.h +++ b/lib/pthread.in.h @@ -408,70 +408,6 @@ pthread_cond_wait (pthread_cond_t *restrict cond, return 0; } -_GL_PTHREAD_INLINE int -pthread_mutexattr_destroy (pthread_mutexattr_t *attr) -{ - return 0; -} - -_GL_PTHREAD_INLINE int -pthread_mutexattr_init (pthread_mutexattr_t *attr) -{ - return 0; -} - -_GL_PTHREAD_INLINE int -pthread_mutexattr_settype (pthread_mutexattr_t *attr, int attr_type) -{ - return 0; -} - -_GL_PTHREAD_INLINE int -pthread_mutex_destroy (pthread_mutex_t *mutex) -{ - /* MUTEX is never seriously used. */ - return 0; -} - -_GL_PTHREAD_INLINE int -pthread_mutex_init (pthread_mutex_t *restrict mutex, - pthread_mutexattr_t const *restrict attr) -{ - /* MUTEX is never seriously used. */ - return 0; -} - -_GL_PTHREAD_INLINE int -pthread_mutex_lock (pthread_mutex_t *mutex) -{ - /* There is only one thread, so it always gets the lock. This - implementation does not support PTHREAD_MUTEX_ERRORCHECK. */ - return 0; -} - -_GL_PTHREAD_INLINE int -pthread_mutex_trylock (pthread_mutex_t *mutex) -{ - return pthread_mutex_lock (mutex); -} - -_GL_PTHREAD_INLINE int -pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime) -{ - /* There is only one thread, so it always gets the lock. This - implementation does not support PTHREAD_MUTEX_ERRORCHECK. */ - return 0; -} - -_GL_PTHREAD_INLINE int -pthread_mutex_unlock (pthread_mutex_t *mutex) -{ - /* There is only one thread, so it always unlocks successfully. - This implementation does not support robust mutexes or - PTHREAD_MUTEX_ERRORCHECK. */ - return 0; -} - # define GNULIB_defined_pthread_functions 1 # endif diff --git a/m4/pthread-mutex.m4 b/m4/pthread-mutex.m4 new file mode 100644 index 0000000000..c7d74f96e5 --- /dev/null +++ b/m4/pthread-mutex.m4 @@ -0,0 +1,44 @@ +# pthread-mutex.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_MUTEX], +[ + 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_MUTEX_INIT=1 + REPLACE_PTHREAD_MUTEXATTR_INIT=1 + REPLACE_PTHREAD_MUTEXATTR_GETTYPE=1 + REPLACE_PTHREAD_MUTEXATTR_SETTYPE=1 + REPLACE_PTHREAD_MUTEXATTR_GETROBUST=1 + REPLACE_PTHREAD_MUTEXATTR_SETROBUST=1 + REPLACE_PTHREAD_MUTEXATTR_DESTROY=1 + REPLACE_PTHREAD_MUTEX_LOCK=1 + REPLACE_PTHREAD_MUTEX_TRYLOCK=1 + REPLACE_PTHREAD_MUTEX_TIMEDLOCK=1 + REPLACE_PTHREAD_MUTEX_UNLOCK=1 + REPLACE_PTHREAD_MUTEX_DESTROY=1 + else + if test $HAVE_PTHREAD_H = 0; then + HAVE_PTHREAD_MUTEX_INIT=0 + HAVE_PTHREAD_MUTEXATTR_INIT=0 + HAVE_PTHREAD_MUTEXATTR_GETTYPE=0 + HAVE_PTHREAD_MUTEXATTR_SETTYPE=0 + HAVE_PTHREAD_MUTEXATTR_GETROBUST=0 + HAVE_PTHREAD_MUTEXATTR_SETROBUST=0 + HAVE_PTHREAD_MUTEXATTR_DESTROY=0 + HAVE_PTHREAD_MUTEX_LOCK=0 + HAVE_PTHREAD_MUTEX_TRYLOCK=0 + dnl HAVE_PTHREAD_MUTEX_TIMEDLOCK is set in pthread_mutex_timedlock.m4. + HAVE_PTHREAD_MUTEX_UNLOCK=0 + HAVE_PTHREAD_MUTEX_DESTROY=0 + fi + fi +]) diff --git a/modules/pthread-mutex b/modules/pthread-mutex new file mode 100644 index 0000000000..8e64a9e2eb --- /dev/null +++ b/modules/pthread-mutex @@ -0,0 +1,33 @@ +Description: +POSIX mutexes (locks). + +Files: +lib/pthread-mutex.c +m4/pthread-mutex.m4 + +Depends-on: +pthread-h +pthread_mutex_timedlock [test $gl_threads_api = posix] +windows-timedmutex [test $gl_threads_api = windows] +windows-timedrecmutex [test $gl_threads_api = windows] + +configure.ac: +gl_PTHREAD_MUTEX +if test $HAVE_PTHREAD_MUTEX_INIT = 0 || test $REPLACE_PTHREAD_MUTEX_INIT = 1; then + AC_LIBOBJ([pthread-mutex]) +fi +gl_PTHREAD_MODULE_INDICATOR([pthread-mutex]) + +Makefile.am: + +Include: + + +Link: +$(LIBTHREAD) or $(LIBMULTITHREAD) + +License: +LGPLv2+ + +Maintainer: +all -- 2.39.5