@@ -1,6 +1,8 @@
#if defined ISO11
macro ONCE_FLAG_INIT
+macro thread_local
+macro-int-constant TSS_DTOR_ITERATIONS
constant thrd_success
constant thrd_busy
@@ -17,6 +19,8 @@ type thrd_start_t
type mtx_t
type once_flag
type cnd_t
+type tss_t
+type tss_dtor_t
function int thrd_create (thrd_t*, thrd_start_t, void*)
function int thrd_equal (thrd_t, thrd_t)
@@ -43,6 +47,11 @@ function int cnd_wait (cnd_t*, mtx_t*)
function int cnd_timedwait (cnd_t*, mtx_t*, const struct timespec*)
function void cnd_destroy (cnd_t*)
+function int tss_create (tss_t*, tss_dtor_t)
+function {void*} tss_get (tss_t)
+function int tss_set (tss_t, void*)
+function void tss_delete (tss_t)
+
#include "time.h-data"
#endif
@@ -143,7 +143,8 @@ libpthread-routines = nptl-init vars events version pt-interp \
thrd_exit thrd_join thrd_sleep thrd_yield \
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 \
@@ -270,7 +270,8 @@ libpthread {
thrd_create; thrd_current; thrd_detach; thrd_equal; thrd_exit; thrd_join;
thrd_sleep; thrd_yield; 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; mtx_destroy;
+ cnd_signal; cnd_timedwait; cnd_wait; mtx_destroy; tss_create; tss_delete;
+ tss_get; tss_set;
}
GLIBC_PRIVATE {
new file mode 100644
@@ -0,0 +1,29 @@
+/* C11 threads thread-specific creation implementation.
+ Copyright (C) 2017 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"
+
+/* Create new thread-specific storage key and stores it in the object
+ pointed by tss_id. If destructor is not NULL, destructor function is
+ called when the thread terminates. */
+int
+tss_create (tss_t *tss_id, tss_dtor_t destructor)
+{
+ int err_code = __pthread_key_create (tss_id, destructor);
+ return thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,27 @@
+/* C11 threads thread-specific delete implementation.
+ Copyright (C) 2017 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"
+
+/* Destroys the thread-specific storage identified by tss_id. The
+ destructor is not called until thrd_exit is called. */
+void
+tss_delete (tss_t tss_id)
+{
+ __pthread_key_delete (tss_id);
+}
new file mode 100644
@@ -0,0 +1,27 @@
+/* C11 threads thread-specific get implementation.
+ Copyright (C) 2017 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"
+
+/* Return the value held in thread-specific storage for the current
+ thread identified by tss_id. */
+void *
+tss_get (tss_t tss_id)
+{
+ return __pthread_getspecific (tss_id);
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* C11 threads thread-specific set implementation.
+ Copyright (C) 2017 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"
+
+/* Sets the value of the thread-specific storage identified by tss_id for
+ the current thread to val. */
+int
+tss_set (tss_t tss_id, void *val)
+{
+ int err_code = __pthread_setspecific (tss_id, val);
+ return thrd_err_map (err_code);
+}
@@ -28,6 +28,10 @@ __BEGIN_DECLS
#include <bits/types/struct_timespec.h>
#define ONCE_FLAG_INIT 0
+#define thread_local _Thread_local
+#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*);
@@ -172,6 +176,25 @@ 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, __destructor function is 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 */