]> Savannah Git Hosting - gnulib.git/commitdiff
pthread-tss: New module.
authorBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:41:00 +0000 (02:41 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 15 Jul 2019 00:41:00 +0000 (02:41 +0200)
* lib/pthread-tss.c: New file.
* m4/pthread-tss.m4: New file.
* modules/pthread-tss: New file.
* doc/posix-functions/pthread_key_create.texi: Mention the new module.
* doc/posix-functions/pthread_setspecific.texi: Likewise.
* doc/posix-functions/pthread_getspecific.texi: Likewise.
* doc/posix-functions/pthread_key_delete.texi: Likewise.

ChangeLog
doc/posix-functions/pthread_getspecific.texi
doc/posix-functions/pthread_key_create.texi
doc/posix-functions/pthread_key_delete.texi
doc/posix-functions/pthread_setspecific.texi
lib/pthread-tss.c [new file with mode: 0644]
m4/pthread-tss.m4 [new file with mode: 0644]
modules/pthread-tss [new file with mode: 0644]

index 23d596ebff60135457beff40beba80bb0b475a48..e3acb25dbd43f9d26114871886386763b5f09da3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-07-14  Bruno Haible  <bruno@clisp.org>
+
+       pthread-tss: New module.
+       * lib/pthread-tss.c: New file.
+       * m4/pthread-tss.m4: New file.
+       * modules/pthread-tss: New file.
+       * doc/posix-functions/pthread_key_create.texi: Mention the new module.
+       * doc/posix-functions/pthread_setspecific.texi: Likewise.
+       * doc/posix-functions/pthread_getspecific.texi: Likewise.
+       * doc/posix-functions/pthread_key_delete.texi: Likewise.
+
 2019-07-14  Bruno Haible  <bruno@clisp.org>
 
        pthread-cond: New module.
index 9951fa69ef8a3bbb7988e5f792156eba727b6935..131af25d92a00bbaafb8b5d02259676280269c9c 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_getspecific.html}
 
-Gnulib module: ---
+Gnulib module: pthread-tss
 
 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 2b1c3d0eb15a88a3b6454495142201aead520a47..db1348148c17e1af54948420a2bf1109d9127dab 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_key_create.html}
 
-Gnulib module: ---
+Gnulib module: pthread-tss
 
 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 685bda761ee8dba1eab7cd56c14c5a555232592d..5f66eb3ad9ea38d941d93cd23998a165ccd85408 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_key_delete.html}
 
-Gnulib module: ---
+Gnulib module: pthread-tss
 
 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 eaf6b4bc433ebe1f66181b4ec86d97982cbe7c2a..5d223b9930a5c999e8a17f565eac1f8d189f4a9b 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_setspecific.html}
 
-Gnulib module: ---
+Gnulib module: pthread-tss
 
 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-tss.c b/lib/pthread-tss.c
new file mode 100644 (file)
index 0000000..c5edb7c
--- /dev/null
@@ -0,0 +1,94 @@
+/* POSIX thread-specific storage.
+   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 3 of the License, 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 Bruno Haible <bruno@clisp.org>, 2019.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <pthread.h>
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+# include "windows-tls.h"
+#else
+# include <stdlib.h>
+#endif
+
+#if (defined _WIN32 && ! defined __CYGWIN__) && USE_WINDOWS_THREADS
+/* Use Windows threads.  */
+
+int
+pthread_key_create (pthread_key_t *keyp, void (*destructor) (void *))
+{
+  return glwthread_tls_key_create (keyp, destructor);
+}
+
+int
+pthread_setspecific (pthread_key_t key, const void *value)
+{
+  return glwthread_tls_set (key, (void *) value);
+}
+
+void *
+pthread_getspecific (pthread_key_t key)
+{
+  return glwthread_tls_get (key);
+}
+
+int
+pthread_key_delete (pthread_key_t key)
+{
+  return glwthread_tls_key_delete (key);
+}
+
+#elif HAVE_PTHREAD_H
+/* Provide workarounds for POSIX threads.  */
+
+#else
+/* Provide a dummy implementation for single-threaded applications.  */
+
+int
+pthread_key_create (pthread_key_t *keyp, void (*destructor) (void *))
+{
+  pthread_key_t key = (void **) malloc (sizeof (void *));
+  if (key == NULL)
+    return ENOMEM;
+  *key = NULL;
+  *keyp = key;
+  return 0;
+}
+
+int
+pthread_setspecific (pthread_key_t key, const void *value)
+{
+  *key = (void *) value;
+  return 0;
+}
+
+void *
+pthread_getspecific (pthread_key_t key)
+{
+  return *key;
+}
+
+int
+pthread_key_delete (pthread_key_t key)
+{
+  free (key);
+  return 0;
+}
+
+#endif
diff --git a/m4/pthread-tss.m4 b/m4/pthread-tss.m4
new file mode 100644 (file)
index 0000000..6ab5247
--- /dev/null
@@ -0,0 +1,28 @@
+# pthread-tss.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_TSS],
+[
+  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_KEY_CREATE=1
+    REPLACE_PTHREAD_SETSPECIFIC=1
+    REPLACE_PTHREAD_GETSPECIFIC=1
+    REPLACE_PTHREAD_KEY_DELETE=1
+  else
+    if test $HAVE_PTHREAD_H = 0; then
+      HAVE_PTHREAD_KEY_CREATE=0
+      HAVE_PTHREAD_SETSPECIFIC=0
+      HAVE_PTHREAD_GETSPECIFIC=0
+      HAVE_PTHREAD_KEY_DELETE=0
+    fi
+  fi
+])
diff --git a/modules/pthread-tss b/modules/pthread-tss
new file mode 100644 (file)
index 0000000..f4e2fde
--- /dev/null
@@ -0,0 +1,31 @@
+Description:
+POSIX thread-specific storage.
+
+Files:
+lib/pthread-tss.c
+m4/pthread-tss.m4
+
+Depends-on:
+pthread-h
+windows-tls     [test $gl_threads_api = windows]
+
+configure.ac:
+gl_PTHREAD_TSS
+if test $HAVE_PTHREAD_KEY_CREATE = 0 || test $REPLACE_PTHREAD_KEY_CREATE = 1; then
+  AC_LIBOBJ([pthread-tss])
+fi
+gl_PTHREAD_MODULE_INDICATOR([pthread-tss])
+
+Makefile.am:
+
+Include:
+<pthread.h>
+
+Link:
+$(LIBMULTITHREAD)
+
+License:
+LGPLv2+
+
+Maintainer:
+all