diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-09-10 23:57:10 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-09-10 23:57:10 +0000 |
commit | 9b0ab39b1c443744bb7b09b03e62e51d78aab527 (patch) | |
tree | 8effaaa2c5359af33e64d0e764739904a46c358f /src/pulsecore/thread-posix.c | |
parent | 3d122d0fee2e3d853ea1a1de297b249f2c125f73 (diff) |
unify static TLS support, make use of gcc __thread attribute if available
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1797 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/pulsecore/thread-posix.c')
-rw-r--r-- | src/pulsecore/thread-posix.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/pulsecore/thread-posix.c b/src/pulsecore/thread-posix.c index 6ad5ac4a..3c69adfb 100644 --- a/src/pulsecore/thread-posix.c +++ b/src/pulsecore/thread-posix.c @@ -49,9 +49,6 @@ struct pa_tls { pthread_key_t key; }; -static pthread_key_t thread_key; -static pthread_once_t thread_once = PTHREAD_ONCE_INIT; - static void thread_free_cb(void *p) { pa_thread *t = p; @@ -62,9 +59,7 @@ static void thread_free_cb(void *p) { pa_xfree(t); } -static void thread_once_func(void) { - pa_assert_se(pthread_key_create(&thread_key, thread_free_cb) == 0); -} +PA_STATIC_TLS_DECLARE(current_thread, thread_free_cb); static void* internal_thread_func(void *userdata) { pa_thread *t = userdata; @@ -72,8 +67,7 @@ static void* internal_thread_func(void *userdata) { t->id = pthread_self(); - pthread_once(&thread_once, thread_once_func); - pthread_setspecific(thread_key, t); + PA_STATIC_TLS_SET(current_thread, t); pa_atomic_inc(&t->running); t->thread_func(t->userdata); @@ -130,11 +124,9 @@ int pa_thread_join(pa_thread *t) { pa_thread* pa_thread_self(void) { pa_thread *t; - pthread_once(&thread_once, thread_once_func); - - if ((t = pthread_getspecific(thread_key))) + if ((t = PA_STATIC_TLS_GET(current_thread))) return t; - + /* This is a foreign thread, let's create a pthread structure to * make sure that we can always return a sensible pointer */ @@ -144,7 +136,7 @@ pa_thread* pa_thread_self(void) { t->userdata = NULL; pa_atomic_store(&t->running, 2); - pthread_setspecific(thread_key, t); + PA_STATIC_TLS_SET(current_thread, t); return t; } |