#include <config.h>
#endif
-#include <fcntl.h>
#include <errno.h>
#include <string.h>
-#include <sys/poll.h>
#include <signal.h>
+
+#ifdef HAVE_PTHREAD
#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>
#include <pulsecore/core-util.h>
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);
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;
}
for (;;) {
char x = 'x';
- if ((s = write(pipe_fd[1], &x, 1)) == 1)
+ if ((s = pa_write(pipe_fd[1], &x, 1, NULL)) == 1)
break;
pa_assert(s < 0);
pfd.fd = pipe_fd[0];
pfd.events = POLLIN;
- if ((k = poll(&pfd, 1, -1)) != 1) {
+ if ((k = pa_poll(&pfd, 1, -1)) != 1) {
pa_assert(k < 0);
pa_assert(errno == EINTR);
- } else if ((s = read(pipe_fd[0], &x, 1)) != 1) {
+ } else if ((s = pa_read(pipe_fd[0], &x, 1, NULL)) != 1) {
pa_assert(s < 0);
pa_assert(errno == EAGAIN);
}
pa_assert(pipe_fd[0] >= 0);
- if ((s = read(pipe_fd[0], &x, sizeof(x))) < 1) {
+ if ((s = pa_read(pipe_fd[0], &x, sizeof(x), NULL)) < 1) {
pa_assert(s < 0);
pa_assert(errno == EAGAIN);
}
static void thread_func(void *u) {
int fd;
char *lf;
+
+#ifdef HAVE_PTHREAD
sigset_t fullset;
/* No signals in this thread please */
sigfillset(&fullset);
pthread_sigmask(SIG_BLOCK, &fullset, NULL);
+#endif
if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) {
pa_log_warn(_("Cannot access autospawn lock."));
static int start_thread(void) {
if (!thread)
- if (!(thread = pa_thread_new(thread_func, NULL)))
+ if (!(thread = pa_thread_new("autospawn", thread_func, NULL)))
return -1;
return 0;
static void create_mutex(void) {
PA_ONCE_BEGIN {
- mutex = pa_mutex_new(FALSE, FALSE);
+ mutex = pa_mutex_new(false, false);
} PA_ONCE_END;
}
return ret;
}
-int pa_autospawn_lock_acquire(pa_bool_t block) {
+int pa_autospawn_lock_acquire(bool block) {
int ret = -1;
create_mutex();
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);