diff --git a/src/pipewire/data-loop.c b/src/pipewire/data-loop.c index c0d349eb2..ca04b9872 100644 --- a/src/pipewire/data-loop.c +++ b/src/pipewire/data-loop.c @@ -197,10 +197,14 @@ SPA_EXPORT int pw_data_loop_start(struct pw_data_loop *loop) { if (!loop->running) { + struct spa_thread_utils *utils; struct spa_thread *thr; loop->running = true; - thr = pw_thread_utils_create(NULL, do_loop, loop); + + if ((utils = loop->thread_utils) == NULL) + utils = pw_thread_utils_get(); + thr = spa_thread_utils_create(utils, NULL, do_loop, loop); loop->thread = (pthread_t)thr; if (thr == NULL) { pw_log_error("%p: can't create thread: %m", loop); @@ -223,6 +227,7 @@ int pw_data_loop_stop(struct pw_data_loop *loop) { pw_log_debug("%p stopping", loop); if (loop->running) { + struct spa_thread_utils *utils; if (loop->cancel) { pw_log_debug("%p cancel", loop); pthread_cancel(loop->thread); @@ -231,7 +236,9 @@ int pw_data_loop_stop(struct pw_data_loop *loop) pw_loop_invoke(loop->loop, do_stop, 1, NULL, 0, false, loop); } pw_log_debug("%p join", loop); - pw_thread_utils_join((struct spa_thread*)loop->thread, NULL); + if ((utils = loop->thread_utils) == NULL) + utils = pw_thread_utils_get(); + spa_thread_utils_join(utils, (struct spa_thread*)loop->thread, NULL); pw_log_debug("%p joined", loop); } pw_log_debug("%p stopped", loop); @@ -273,3 +280,17 @@ int pw_data_loop_invoke(struct pw_data_loop *loop, res = func(loop->loop->loop, false, seq, data, size, user_data); return res; } + +/** Set a thread utils implementation. + * \param loop the data loop to set the thread utils on + * \param impl the thread utils implementation + * + * This configures a custom spa_thread_utils implementation for this data + * loop. Use NULL to restore the system default implementation. + */ +SPA_EXPORT +void pw_data_loop_set_thread_utils(struct pw_data_loop *loop, + struct spa_thread_utils *impl) +{ + loop->thread_utils = impl; +} diff --git a/src/pipewire/data-loop.h b/src/pipewire/data-loop.h index 307087d53..a459c19e5 100644 --- a/src/pipewire/data-loop.h +++ b/src/pipewire/data-loop.h @@ -30,6 +30,7 @@ extern "C" { #endif #include +#include /** \defgroup pw_data_loop Data Loop * @@ -97,6 +98,10 @@ int pw_data_loop_invoke(struct pw_data_loop *loop, spa_invoke_func_t func, uint32_t seq, const void *data, size_t size, bool block, void *user_data); +/** Set a custom spa_thread_utils for this loop. Setting NULL restores the + * system default implementation. Since 0.3.50 */ +void pw_data_loop_set_thread_utils(struct pw_data_loop *loop, + struct spa_thread_utils *impl); /** * \} */ diff --git a/src/pipewire/private.h b/src/pipewire/private.h index b5ae51ab8..a8f2c3865 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -483,6 +483,8 @@ struct pw_data_loop { struct spa_hook_list listener_list; + struct spa_thread_utils *thread_utils; + pthread_t thread; unsigned int cancel:1; unsigned int created:1;