From 6b73d49780b8047d6b5c36fd255fc7e15ccf8bff Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 5 Jul 2021 10:10:36 +0200 Subject: [PATCH] data-loop: use new thread interface --- src/pipewire/data-loop.c | 17 ++++++++++------- src/pipewire/data-loop.h | 3 +-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pipewire/data-loop.c b/src/pipewire/data-loop.c index b3aea0699..2598fcb83 100644 --- a/src/pipewire/data-loop.c +++ b/src/pipewire/data-loop.c @@ -29,6 +29,7 @@ #include "pipewire/log.h" #include "pipewire/data-loop.h" #include "pipewire/private.h" +#include "pipewire/thread.h" #define NAME "data-loop" @@ -203,13 +204,15 @@ SPA_EXPORT int pw_data_loop_start(struct pw_data_loop *loop) { if (!loop->running) { - int err; + struct pw_thread *thr; loop->running = true; - if ((err = pthread_create(&loop->thread, NULL, do_loop, loop)) != 0) { - pw_log_error(NAME" %p: can't create thread: %s", loop, strerror(err)); + thr = pw_thread_utils_create(NULL, do_loop, loop); + loop->thread = (pthread_t)thr; + if (thr == NULL) { + pw_log_error(NAME" %p: can't create thread: %m", loop); loop->running = false; - return -err; + return -errno; } } return 0; @@ -235,7 +238,7 @@ int pw_data_loop_stop(struct pw_data_loop *loop) pthread_cancel(loop->thread); } pw_log_debug(NAME": %p join", loop); - pthread_join(loop->thread, NULL); + pw_thread_utils_join((struct pw_thread*)loop->thread, NULL); pw_log_debug(NAME": %p joined", loop); } pw_log_debug(NAME": %p stopped", loop); @@ -260,9 +263,9 @@ bool pw_data_loop_in_thread(struct pw_data_loop * loop) * On posix based systems this returns a pthread_t * */ SPA_EXPORT -void *pw_data_loop_get_thread(struct pw_data_loop * loop) +struct pw_thread *pw_data_loop_get_thread(struct pw_data_loop * loop) { - return loop->running ? &loop->thread : NULL; + return loop->running ? (struct pw_thread*)loop->thread : NULL; } SPA_EXPORT diff --git a/src/pipewire/data-loop.h b/src/pipewire/data-loop.h index cb763ce7f..966bc72c8 100644 --- a/src/pipewire/data-loop.h +++ b/src/pipewire/data-loop.h @@ -86,9 +86,8 @@ int pw_data_loop_stop(struct pw_data_loop *loop); /** Check if the current thread is the processing thread */ bool pw_data_loop_in_thread(struct pw_data_loop *loop); - /** Get the thread object */ -void *pw_data_loop_get_thread(struct pw_data_loop *loop); +struct pw_thread *pw_data_loop_get_thread(struct pw_data_loop *loop); /** invoke func in the context of the thread or in the caller thread when * the loop is not running. Since 0.3.3 */