]> pd.if.org Git - pdclib.old/commitdiff
pthread c11 threading backend: add support for thread specific data
authorOwen Shepherd <owen.shepherd@e43.eu>
Mon, 31 Dec 2012 19:17:07 +0000 (19:17 +0000)
committerOwen Shepherd <owen.shepherd@e43.eu>
Mon, 31 Dec 2012 19:17:07 +0000 (19:17 +0000)
opt/pthreads/tss_create.c [new file with mode: 0644]
opt/pthreads/tss_delete.c [new file with mode: 0644]
opt/pthreads/tss_get.c [new file with mode: 0644]
opt/pthreads/tss_set.c [new file with mode: 0644]

diff --git a/opt/pthreads/tss_create.c b/opt/pthreads/tss_create.c
new file mode 100644 (file)
index 0000000..e51a09e
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef REGTEST
+#include <threads.h>
+#include <pthread.h>
+
+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 (file)
index 0000000..906c761
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef REGTEST
+#include <threads.h>
+#include <pthread.h>
+#include <assert.h>
+
+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 (file)
index 0000000..cff00ea
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef REGTEST
+#include <threads.h>
+#include <pthread.h>
+
+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 (file)
index 0000000..99895e0
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef REGTEST
+#include <threads.h>
+#include <pthread.h>
+
+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