about summary refs log tree commit diff
path: root/nptl
diff options
context:
space:
mode:
Diffstat (limited to 'nptl')
-rw-r--r--nptl/Makefile3
-rw-r--r--nptl/Versions2
-rw-r--r--nptl/threads.h28
-rw-r--r--nptl/tss_create.c31
-rw-r--r--nptl/tss_delete.c25
-rw-r--r--nptl/tss_get.c25
-rw-r--r--nptl/tss_set.c26
7 files changed, 138 insertions, 2 deletions
diff --git a/nptl/Makefile b/nptl/Makefile
index 0864aee581..e331bf78d6 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -144,7 +144,8 @@ libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \
 		      thrd_create thrd_detach thrd_exit thrd_join \
 		      mtx_destroy mtx_init mtx_lock mtx_timedlock \
 		      mtx_trylock mtx_unlock call_once cnd_broadcast \
-		      cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait
+		      cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait \
+		      tss_create tss_delete tss_get tss_set
 #		      pthread_setuid pthread_seteuid pthread_setreuid \
 #		      pthread_setresuid \
 #		      pthread_setgid pthread_setegid pthread_setregid \
diff --git a/nptl/Versions b/nptl/Versions
index 9c38d67e72..e7f691da7a 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -274,7 +274,7 @@ libpthread {
     thrd_create; thrd_detach; thrd_exit; thrd_join;
     mtx_init; mtx_lock; mtx_timedlock; mtx_trylock; mtx_unlock; mtx_destroy;
     call_once; cnd_broadcast; cnd_destroy; cnd_init; cnd_signal;
-    cnd_timedwait; cnd_wait;
+    cnd_timedwait; cnd_wait; tss_create; tss_delete; tss_get; tss_set;
   }
 
   GLIBC_PRIVATE {
diff --git a/nptl/threads.h b/nptl/threads.h
index e46b1b7f32..9800f93aa7 100644
--- a/nptl/threads.h
+++ b/nptl/threads.h
@@ -27,6 +27,14 @@ __BEGIN_DECLS
 #include <bits/pthreadtypes-arch.h>
 #include <bits/types/struct_timespec.h>
 
+#ifndef __cplusplus
+# define thread_local _Thread_local
+#endif
+
+#define TSS_DTOR_ITERATIONS 4
+typedef unsigned int tss_t;
+typedef void (*tss_dtor_t) (void*);
+
 typedef unsigned long int thrd_t;
 typedef int (*thrd_start_t) (void*);
 
@@ -174,6 +182,26 @@ extern int cnd_timedwait (cnd_t *__restrict __cond,
    resources.  */
 extern void cnd_destroy (cnd_t *__COND);
 
+
+/* Thread specific storage functions.  */
+
+/* Create new thread-specific storage key and stores it in the object pointed
+   by __TSS_ID.  If __DESTRUCTOR is not NULL, the function will be called when
+   the thread terminates.  */
+extern int tss_create (tss_t *__tss_id, tss_dtor_t __destructor);
+
+/* Return the value held in thread-specific storage for the current thread
+   identified by __TSS_ID.  */
+extern void *tss_get (tss_t __tss_id);
+
+/* Sets the value of the thread-specific storage identified by __TSS_ID for
+   the current thread to __VAL.  */
+extern int tss_set (tss_t __tss_id, void *__val);
+
+/* Destroys the thread-specific storage identified by __TSS_ID.  The
+   destructor is not called until thrd_exit is called.  */
+extern void tss_delete (tss_t __tss_id);
+
 __END_DECLS
 
 #endif /* _THREADS_H */
diff --git a/nptl/tss_create.c b/nptl/tss_create.c
new file mode 100644
index 0000000000..c1b148c1f4
--- /dev/null
+++ b/nptl/tss_create.c
@@ -0,0 +1,31 @@
+/* C11 threads thread-specific creation implementation.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "thrd_priv.h"
+
+int
+tss_create (tss_t *tss_id, tss_dtor_t destructor)
+{
+  _Static_assert (sizeof (tss_t) == sizeof (pthread_key_t),
+		  "sizeof (tss_t) != sizeof (pthread_key_t)");
+  _Static_assert (TSS_DTOR_ITERATIONS == PTHREAD_DESTRUCTOR_ITERATIONS,
+		  "TSS_DTOR_ITERATIONS != PTHREAD_DESTRUCTOR_ITERATIONS");
+
+  int err_code = __pthread_key_create (tss_id, destructor);
+  return thrd_err_map (err_code);
+}
diff --git a/nptl/tss_delete.c b/nptl/tss_delete.c
new file mode 100644
index 0000000000..0fc2975242
--- /dev/null
+++ b/nptl/tss_delete.c
@@ -0,0 +1,25 @@
+/* C11 threads thread-specific delete implementation.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "thrd_priv.h"
+
+void
+tss_delete (tss_t tss_id)
+{
+  __pthread_key_delete (tss_id);
+}
diff --git a/nptl/tss_get.c b/nptl/tss_get.c
new file mode 100644
index 0000000000..5e09766ec1
--- /dev/null
+++ b/nptl/tss_get.c
@@ -0,0 +1,25 @@
+/* C11 threads thread-specific get implementation.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "thrd_priv.h"
+
+void *
+tss_get (tss_t tss_id)
+{
+  return __pthread_getspecific (tss_id);
+}
diff --git a/nptl/tss_set.c b/nptl/tss_set.c
new file mode 100644
index 0000000000..03973d92c9
--- /dev/null
+++ b/nptl/tss_set.c
@@ -0,0 +1,26 @@
+/* C11 threads thread-specific set implementation.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "thrd_priv.h"
+
+int
+tss_set (tss_t tss_id, void *val)
+{
+  int err_code = __pthread_setspecific (tss_id, val);
+  return thrd_err_map (err_code);
+}