From fd89f130aedf49fbdb3e4f5a24c9cedb56eea22e Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Mon, 31 Dec 2012 19:17:07 +0000 Subject: [PATCH] pthread c11 threading backend: add support for thread specific data --- opt/pthreads/tss_create.c | 25 +++++++++++++++++++++++++ opt/pthreads/tss_delete.c | 21 +++++++++++++++++++++ opt/pthreads/tss_get.c | 31 +++++++++++++++++++++++++++++++ opt/pthreads/tss_set.c | 25 +++++++++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 opt/pthreads/tss_create.c create mode 100644 opt/pthreads/tss_delete.c create mode 100644 opt/pthreads/tss_get.c create mode 100644 opt/pthreads/tss_set.c diff --git a/opt/pthreads/tss_create.c b/opt/pthreads/tss_create.c new file mode 100644 index 0000000..e51a09e --- /dev/null +++ b/opt/pthreads/tss_create.c @@ -0,0 +1,25 @@ +#ifndef REGTEST +#include +#include + +int tss_create(tss_t *key, tss_dtor_t dtor) +{ + switch(pthread_key_create(key, dtor)) { + case 0: + return thrd_success; + default: + return thrd_error; + } +} +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +/* Tested in tss_get.c */ +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/opt/pthreads/tss_delete.c b/opt/pthreads/tss_delete.c new file mode 100644 index 0000000..906c761 --- /dev/null +++ b/opt/pthreads/tss_delete.c @@ -0,0 +1,21 @@ +#ifndef REGTEST +#include +#include +#include + +void tss_delete(tss_t key) +{ + assert(pthread_key_delete(key) == 0); +} +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +/* Tested in tss_get.c */ +int main( void ) +{ + return TEST_RESULTS; +} + +#endif diff --git a/opt/pthreads/tss_get.c b/opt/pthreads/tss_get.c new file mode 100644 index 0000000..cff00ea --- /dev/null +++ b/opt/pthreads/tss_get.c @@ -0,0 +1,31 @@ +#ifndef REGTEST +#include +#include + +void *tss_get(tss_t key) +{ + return pthread_getspecific(key); +} +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +#ifndef REGTEST +static tss_t key; +static char v; +#endif + +int main( void ) +{ +#ifndef REGTEST + TESTCASE(tss_create(&key, NULL) == thrd_success); + TESTCASE(tss_get(key) == NULL); + TESTCASE(tss_set(key, &v) == thrd_success); + TESTCASE(tss_get(key) == &v); + tss_delete(key); +#endif + return TEST_RESULTS; +} + +#endif diff --git a/opt/pthreads/tss_set.c b/opt/pthreads/tss_set.c new file mode 100644 index 0000000..99895e0 --- /dev/null +++ b/opt/pthreads/tss_set.c @@ -0,0 +1,25 @@ +#ifndef REGTEST +#include +#include + +int tss_set(tss_t key, void *val) +{ + switch(pthread_setspecific(key, val)) { + case 0: + return thrd_success; + default: + return thrd_error; + } +} +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +/* Tested in tss_get.c */ +int main( void ) +{ + return TEST_RESULTS; +} + +#endif -- 2.40.0