summaryrefslogtreecommitdiff
path: root/tsd.c
diff options
context:
space:
mode:
authorbje <bje>1998-07-19 12:43:13 +0000
committerbje <bje>1998-07-19 12:43:13 +0000
commit5468a2687ea9242ee79bcf2ba303a2578bfb24b3 (patch)
tree5b3562e3a09cf93c5558a0eb42358153afaef259 /tsd.c
parent8ceeeb02f5dd8ac90c98b348f169250fc1af34e4 (diff)
1998-07-19 Ben Elliston <bje@cygnus.com>
* tsd.c (pthread_key_create): Implement. (pthread_setspecific): Likewise. (pthread_getspecific): Likewise. (pthread_key_delete): Likewise.
Diffstat (limited to 'tsd.c')
-rw-r--r--tsd.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tsd.c b/tsd.c
new file mode 100644
index 0000000..e17caf2
--- /dev/null
+++ b/tsd.c
@@ -0,0 +1,56 @@
+/*
+ * tsd.c
+ *
+ * Description:
+ * POSIX thread functions which implement thread-specific data (TSD).
+ */
+
+#include "pthread.h"
+
+int
+pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
+{
+ DWORD index;
+
+ /* FIXME: the destructor function is ignored for now. This needs to
+ be managed via the same cleanup handler mechanism as user-define
+ cleanup handlers during a thread exit. */
+
+ if (destructor != NULL)
+ {
+ return EINVAL;
+ }
+
+ index = TlsAlloc();
+ if (index == 0xFFFFFFFF)
+ {
+ return EAGAIN;
+ }
+
+ /* Only modify the `key' parameter if allocation was successful. */
+ *key = index;
+
+ return 0;
+}
+
+int
+pthread_setspecific(pthread_key_t key, void *value)
+{
+ return (TlsSetValue(key, value) == FALSE) ? EINVAL : 0;
+}
+
+void *
+pthread_getspecific(pthread_key_t key)
+{
+ /* FIXME: this code assumes that TlsGetValue returns NULL if the key
+ is not present in the TLS structure. Confirm. */
+
+ return TlsGetValue(key);
+}
+
+int
+pthread_key_delete(pthread_key_t key)
+{
+ return (TlsFree(key) == FALSE) ? EINVAL : 0;
+}
+