]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/thread-posix.c
memblock: rearrange locking order
[pulseaudio] / src / pulsecore / thread-posix.c
index 20ed16d95c9deb9472b28590d87592124002aab4..fdab270f06a80181b759f2b44ac95a82942a4fa5 100644 (file)
@@ -6,7 +6,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
@@ -41,6 +41,7 @@ struct pa_thread {
     pa_thread_func_t thread_func;
     void *userdata;
     pa_atomic_t running;
+    pa_bool_t joined;
 };
 
 struct pa_tls {
@@ -82,6 +83,7 @@ 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;
+    t->joined = FALSE;
     pa_atomic_store(&t->running, 0);
 
     if (pthread_create(&t->id, NULL, internal_thread_func, t) < 0) {
@@ -115,7 +117,12 @@ void pa_thread_free(pa_thread *t) {
 
 int pa_thread_join(pa_thread *t) {
     pa_assert(t);
+    pa_assert(t->thread_func);
+
+    if (t->joined)
+        return -1;
 
+    t->joined = TRUE;
     return pthread_join(t->id, NULL);
 }
 
@@ -132,6 +139,7 @@ pa_thread* pa_thread_self(void) {
     t->id = pthread_self();
     t->thread_func = NULL;
     t->userdata = NULL;
+    t->joined = TRUE;
     pa_atomic_store(&t->running, 2);
 
     PA_STATIC_TLS_SET(current_thread, t);
@@ -192,4 +200,3 @@ void *pa_tls_set(pa_tls *t, void *userdata) {
     pa_assert_se(pthread_setspecific(t->key, userdata) == 0);
     return r;
 }
-