]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/lock-autospawn.c
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / lock-autospawn.c
index a9c942fbb222cefb6266a7325ea4aaa490d2096f..82518dbac1139eb576176f98064c731b68fe55cc 100644 (file)
@@ -23,7 +23,6 @@
 #include <config.h>
 #endif
 
-#include <fcntl.h>
 #include <errno.h>
 #include <string.h>
 #include <signal.h>
 #include <pthread.h>
 #endif
 
-#include <pulse/i18n.h>
+#include <pulse/gccmacro.h>
 #include <pulse/xmalloc.h>
 
+#include <pulsecore/i18n.h>
 #include <pulsecore/poll.h>
 #include <pulsecore/mutex.h>
 #include <pulsecore/thread.h>
@@ -96,13 +96,13 @@ static int ref(void) {
     pa_make_fd_nonblock(pipe_fd[1]);
     pa_make_fd_nonblock(pipe_fd[0]);
 
-    lock_fd_mutex = pa_mutex_new(FALSE, FALSE);
+    lock_fd_mutex = pa_mutex_new(false, false);
 
     n_ref = 1;
     return 0;
 }
 
-static void unref(pa_bool_t after_fork) {
+static void unref(bool after_fork) {
 
     pa_assert(n_ref > 0);
     pa_assert(pipe_fd[0] >= 0);
@@ -114,8 +114,15 @@ static void unref(pa_bool_t after_fork) {
     if (n_ref > 0)
         return;
 
+    /* Join threads only in the process the new thread was created in
+     * to avoid undefined behaviour.
+     * POSIX.1-2008 XSH 2.9.2 Thread IDs: "applications should only assume
+     * that thread IDs are usable and unique within a single process." */
     if (thread) {
-        pa_thread_free(thread);
+        if (after_fork)
+            pa_thread_free_nojoin(thread);
+       else
+            pa_thread_free(thread);
         thread = NULL;
     }
 
@@ -257,7 +264,7 @@ static int start_thread(void) {
 
 static void create_mutex(void) {
     PA_ONCE_BEGIN {
-        mutex = pa_mutex_new(FALSE, FALSE);
+        mutex = pa_mutex_new(false, false);
     } PA_ONCE_END;
 }
 
@@ -282,7 +289,7 @@ int pa_autospawn_lock_init(void) {
     return ret;
 }
 
-int pa_autospawn_lock_acquire(pa_bool_t block) {
+int pa_autospawn_lock_acquire(bool block) {
     int ret = -1;
 
     create_mutex();
@@ -345,7 +352,7 @@ void pa_autospawn_lock_release(void) {
     pa_mutex_unlock(mutex);
 }
 
-void pa_autospawn_lock_done(pa_bool_t after_fork) {
+void pa_autospawn_lock_done(bool after_fork) {
 
     create_mutex();
     pa_mutex_lock(mutex);