From 2f6cc4f8fa8d806ef6120887cd3aed62b1b072c0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 30 Aug 2006 17:12:35 +0000 Subject: fix handling of "running" variable git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1349 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/thread-posix.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/pulsecore/thread-posix.c') diff --git a/src/pulsecore/thread-posix.c b/src/pulsecore/thread-posix.c index 54f21b75..b634a6f6 100644 --- a/src/pulsecore/thread-posix.c +++ b/src/pulsecore/thread-posix.c @@ -66,9 +66,9 @@ static void* internal_thread_func(void *userdata) { ASSERT_SUCCESS(pthread_once(&thread_tls_once, thread_tls_once_func)); pa_tls_set(thread_tls, t); - AO_store_release_write(&t->running, 1); + AO_fetch_and_add1_full(&t->running); t->thread_func(t->userdata); - AO_store_release_write(&t->running, 0); + AO_fetch_and_add_full(&t->running, (AO_t) -2); return NULL; } @@ -79,19 +79,24 @@ pa_thread* pa_thread_new(pa_thread_func_t thread_func, void *userdata) { t = pa_xnew(pa_thread, 1); t->thread_func = thread_func; t->userdata = userdata; + AO_store_full(&t->running, 0); if (pthread_create(&t->id, NULL, internal_thread_func, t) < 0) { pa_xfree(t); return NULL; } + AO_fetch_and_add1_full(&t->running); + return t; } int pa_thread_is_running(pa_thread *t) { + AO_t r; assert(t); - return !!AO_load_acquire_read(&t->running); + r = AO_load_full(&t->running); + return r == 1 || r == 2; } void pa_thread_free(pa_thread *t) { -- cgit