From e16f70f45210294321a88f23c85ac45046577adc Mon Sep 17 00:00:00 2001 From: Jens Gustedt Date: Sat, 6 Sep 2014 21:32:53 -0400 Subject: [PATCH] add C11 thread functions operating on tss_t and once_flag These all have POSIX equivalents, but aside from tss_get, they all have minor changes to the signature or return value and thus need to exist as separate functions. --- src/thread/call_once.c | 8 ++++++++ src/thread/pthread_getspecific.c | 2 ++ src/thread/tss_create.c | 11 +++++++++++ src/thread/tss_delete.c | 8 ++++++++ src/thread/tss_set.c | 13 +++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 src/thread/call_once.c create mode 100644 src/thread/tss_create.c create mode 100644 src/thread/tss_delete.c create mode 100644 src/thread/tss_set.c diff --git a/src/thread/call_once.c b/src/thread/call_once.c new file mode 100644 index 00000000..a7bc9353 --- /dev/null +++ b/src/thread/call_once.c @@ -0,0 +1,8 @@ +#include + +int __pthread_once(once_flag *, void (*)(void)); + +void call_once(once_flag *flag, void (*func)(void)) +{ + __pthread_once(flag, func); +} diff --git a/src/thread/pthread_getspecific.c b/src/thread/pthread_getspecific.c index d3d09fa2..d9342a56 100644 --- a/src/thread/pthread_getspecific.c +++ b/src/thread/pthread_getspecific.c @@ -1,4 +1,5 @@ #include "pthread_impl.h" +#include static void *__pthread_getspecific(pthread_key_t k) { @@ -7,3 +8,4 @@ static void *__pthread_getspecific(pthread_key_t k) } weak_alias(__pthread_getspecific, pthread_getspecific); +weak_alias(__pthread_getspecific, tss_get); diff --git a/src/thread/tss_create.c b/src/thread/tss_create.c new file mode 100644 index 00000000..251d22b9 --- /dev/null +++ b/src/thread/tss_create.c @@ -0,0 +1,11 @@ +#include + +int __pthread_key_create(tss_t *, void (*)(void *)); + +int tss_create(tss_t *tss, tss_dtor_t dtor) +{ + /* Different error returns are possible. C glues them together into + * just failure notification. Can't be optimized to a tail call, + * unless thrd_error equals EAGAIN. */ + return __pthread_key_create(tss, dtor) ? thrd_error : thrd_success; +} diff --git a/src/thread/tss_delete.c b/src/thread/tss_delete.c new file mode 100644 index 00000000..35db1032 --- /dev/null +++ b/src/thread/tss_delete.c @@ -0,0 +1,8 @@ +#include + +int __pthread_key_delete(tss_t k); + +void tss_delete(tss_t key) +{ + __pthread_key_delete(key); +} diff --git a/src/thread/tss_set.c b/src/thread/tss_set.c new file mode 100644 index 00000000..70c4fb72 --- /dev/null +++ b/src/thread/tss_set.c @@ -0,0 +1,13 @@ +#include "pthread_impl.h" +#include + +int tss_set(tss_t k, void *x) +{ + struct pthread *self = __pthread_self(); + /* Avoid unnecessary COW */ + if (self->tsd[k] != x) { + self->tsd[k] = x; + self->tsd_used = 1; + } + return thrd_success; +} -- 2.25.1