>From ee2f4139e12114621dc1e4db54c0b1658a9fadac Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 20 Jun 2019 04:34:49 +0200 Subject: [PATCH 21/26] tss: New module. * lib/tss.c: New file. * modules/tss: New file. * doc/posix-functions/tss_create.texi: Mention the new module. * doc/posix-functions/tss_set.texi: Likewise. * doc/posix-functions/tss_get.texi: Likewise. * doc/posix-functions/tss_delete.texi: Likewise. --- ChangeLog | 10 ++++ doc/posix-functions/tss_create.texi | 8 +-- doc/posix-functions/tss_delete.texi | 8 +-- doc/posix-functions/tss_get.texi | 8 +-- doc/posix-functions/tss_set.texi | 8 +-- lib/tss.c | 108 ++++++++++++++++++++++++++++++++++++ modules/tss | 30 ++++++++++ 7 files changed, 164 insertions(+), 16 deletions(-) create mode 100644 lib/tss.c create mode 100644 modules/tss diff --git a/ChangeLog b/ChangeLog index 68eeea7..4c75b69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2019-06-20 Bruno Haible + tss: New module. + * lib/tss.c: New file. + * modules/tss: New file. + * doc/posix-functions/tss_create.texi: Mention the new module. + * doc/posix-functions/tss_set.texi: Likewise. + * doc/posix-functions/tss_get.texi: Likewise. + * doc/posix-functions/tss_delete.texi: Likewise. + +2019-06-20 Bruno Haible + cnd: New module. * lib/cnd.c: New file. * modules/cnd: New file. diff --git a/doc/posix-functions/tss_create.texi b/doc/posix-functions/tss_create.texi index 833cd87..86fab4e 100644 --- a/doc/posix-functions/tss_create.texi +++ b/doc/posix-functions/tss_create.texi @@ -10,15 +10,15 @@ Documentation:@* @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Thread_002dlocal-Storage.html}. @end ifnotinfo -Gnulib module: --- +Gnulib module: tss Portability problems fixed by Gnulib: @itemize +@item +This function is missing on many platforms: +glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on many platforms: -glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0. @end itemize diff --git a/doc/posix-functions/tss_delete.texi b/doc/posix-functions/tss_delete.texi index c122828..8527324 100644 --- a/doc/posix-functions/tss_delete.texi +++ b/doc/posix-functions/tss_delete.texi @@ -10,15 +10,15 @@ Documentation:@* @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Thread_002dlocal-Storage.html}. @end ifnotinfo -Gnulib module: --- +Gnulib module: tss Portability problems fixed by Gnulib: @itemize +@item +This function is missing on many platforms: +glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on many platforms: -glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0. @end itemize diff --git a/doc/posix-functions/tss_get.texi b/doc/posix-functions/tss_get.texi index 0cc14d8..b8109cb 100644 --- a/doc/posix-functions/tss_get.texi +++ b/doc/posix-functions/tss_get.texi @@ -10,15 +10,15 @@ Documentation:@* @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Thread_002dlocal-Storage.html}. @end ifnotinfo -Gnulib module: --- +Gnulib module: tss Portability problems fixed by Gnulib: @itemize +@item +This function is missing on many platforms: +glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on many platforms: -glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0. @end itemize diff --git a/doc/posix-functions/tss_set.texi b/doc/posix-functions/tss_set.texi index 533ad89..d0091f0 100644 --- a/doc/posix-functions/tss_set.texi +++ b/doc/posix-functions/tss_set.texi @@ -10,15 +10,15 @@ Documentation:@* @url{https://www.gnu.org/software/libc/manual/html_node/ISO-C-Thread_002dlocal-Storage.html}. @end ifnotinfo -Gnulib module: --- +Gnulib module: tss Portability problems fixed by Gnulib: @itemize +@item +This function is missing on many platforms: +glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on many platforms: -glibc 2.27, Mac OS X 10.5, FreeBSD 9.3, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 9.0. @end itemize diff --git a/lib/tss.c b/lib/tss.c new file mode 100644 index 0000000..d8c0bb5 --- /dev/null +++ b/lib/tss.c @@ -0,0 +1,108 @@ +/* ISO C 11 thread-specific storage in multithreaded situations. + Copyright (C) 2005-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 . */ + +/* Written by Bruno Haible , 2005, 2019. */ + +#include + +#include + +#include + +#if defined _WIN32 && ! defined __CYGWIN__ +/* Use Windows threads. */ + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include + +#else +/* Use POSIX threads. */ + +# include + +#endif + +#if defined _WIN32 && ! defined __CYGWIN__ +/* Use Windows threads. */ + +int +tss_create (tss_t *keyp, tss_dtor_t destructor) +{ + int err = glwthread_tls_key_create (keyp, destructor); + if (err == 0) + return thrd_success; + else + { + memset (keyp, '\0', sizeof (tss_t)); + return thrd_error; + } +} + +int +tss_set (tss_t key, void *value) +{ + int err = glwthread_tls_set (key, value); + return (err == 0 ? thrd_success : thrd_error); +} + +void * +tss_get (tss_t key) +{ + return glwthread_tls_get (key); +} + +void +tss_delete (tss_t key) +{ + glwthread_tls_key_delete (key); +} + +#else +/* Use POSIX threads. */ + +int +tss_create (tss_t *keyp, tss_dtor_t destructor) +{ + int err = pthread_key_create (keyp, destructor); + if (err == 0) + return thrd_success; + else + { + memset (keyp, '\0', sizeof (tss_t)); + return thrd_error; + } +} + +int +tss_set (tss_t key, void *value) +{ + int err = pthread_setspecific (key, value); + return (err == 0 ? thrd_success : thrd_error); +} + +void * +tss_get (tss_t key) +{ + return pthread_getspecific (key); +} + +void +tss_delete (tss_t key) +{ + pthread_key_delete (key); +} + +#endif diff --git a/modules/tss b/modules/tss new file mode 100644 index 0000000..4a28200 --- /dev/null +++ b/modules/tss @@ -0,0 +1,30 @@ +Description: +ISO C 11 thread-specific storage functions. + +Files: +lib/tss.c + +Depends-on: +threads-h +windows-tls + +configure.ac: +AC_REQUIRE([gl_THREADS_H]) +if test $HAVE_THREADS_H = 0; then + AC_LIBOBJ([tss]) +fi +gl_THREADS_MODULE_INDICATOR([tss]) + +Makefile.am: + +Include: + + +Link: +$(LTLIBSTDTHREAD) when linking with libtool, $(LIBSTDTHREAD) otherwise + +License: +LGPLv2+ + +Maintainer: +all -- 2.7.4