diff --git a/headers/posix/pthread.h b/headers/posix/pthread.h index d57165926d..bf8edd1fc5 100644 --- a/headers/posix/pthread.h +++ b/headers/posix/pthread.h @@ -127,6 +127,12 @@ extern pthread_t pthread_self(void); extern int pthread_kill(pthread_t thread, int sig); +/* thread specific data functions */ +extern int pthread_key_create(pthread_key_t *key, void (*destructor)(void*)); +extern int pthread_key_delete(pthread_key_t key); +extern void *pthread_getspecific(pthread_key_t key); +extern int pthread_setspecific(pthread_key_t key, const void *value); + #ifdef __cplusplus } #endif diff --git a/src/system/libroot/posix/pthread/Jamfile b/src/system/libroot/posix/pthread/Jamfile index ab4ef86f91..964b3cdf2e 100644 --- a/src/system/libroot/posix/pthread/Jamfile +++ b/src/system/libroot/posix/pthread/Jamfile @@ -6,6 +6,7 @@ MergeObject posix_pthread.o : pthread.c pthread_atfork.c pthread_attr.c + pthread_key.c pthread_mutex.c pthread_mutexattr.c ; diff --git a/src/system/libroot/posix/pthread/pthread.c b/src/system/libroot/posix/pthread/pthread.c index 7897534d1f..7ffabf0249 100644 --- a/src/system/libroot/posix/pthread/pthread.c +++ b/src/system/libroot/posix/pthread/pthread.c @@ -73,3 +73,10 @@ pthread_kill(pthread_t thread, int sig) return kill(thread, sig); } + +int +pthread_detach(pthread_t thread) +{ + return B_NOT_ALLOWED; +} + diff --git a/src/system/libroot/posix/pthread/pthread_key.c b/src/system/libroot/posix/pthread/pthread_key.c new file mode 100644 index 0000000000..010fbc901a --- /dev/null +++ b/src/system/libroot/posix/pthread/pthread_key.c @@ -0,0 +1,45 @@ +/* +** Copyright 2006, Jérôme Duval. All rights reserved. +** Distributed under the terms of the MIT License. +*/ + + +#include +#include +#include "pthread_private.h" + +int +pthread_key_create(pthread_key_t *key, void (*destructor)(void*)) +{ + if (key == NULL) + return B_BAD_VALUE; + *key = tls_allocate(); + if (*key > 0) + return B_OK; + return *key; +} + + +int +pthread_key_delete(pthread_key_t key) +{ + // we don't check if the key is valid + return B_OK; +} + + +void * +pthread_getspecific(pthread_key_t key) +{ + return tls_get(key); +} + + +int +pthread_setspecific(pthread_key_t key, const void *value) +{ + // we don't check if the key is valid + tls_set(key, (void *)value); + return B_OK; +} +