From cec26494f82eaf4c8d0a21d40a171b2ee3869ed0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 30 Apr 2020 11:54:15 +0200 Subject: [PATCH] data-loop: add function to invoke Add function that invokes the given function in the context of the thread or the caller thread depending on if the thread is running. --- src/pipewire/data-loop.c | 13 +++++++++++++ src/pipewire/data-loop.h | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/pipewire/data-loop.c b/src/pipewire/data-loop.c index a3c01e0d9..31e9cf253 100644 --- a/src/pipewire/data-loop.c +++ b/src/pipewire/data-loop.c @@ -252,3 +252,16 @@ bool pw_data_loop_in_thread(struct pw_data_loop * loop) { return pthread_equal(loop->thread, pthread_self()); } + +SPA_EXPORT +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) +{ + int res; + if (loop->running) + res = pw_loop_invoke(loop->loop, func, seq, data, size, block, user_data); + else + res = func(loop->loop->loop, false, seq, data, size, user_data); + return res; +} diff --git a/src/pipewire/data-loop.h b/src/pipewire/data-loop.h index f736f8e49..928c598ed 100644 --- a/src/pipewire/data-loop.h +++ b/src/pipewire/data-loop.h @@ -82,6 +82,12 @@ 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); +/** invoke func in the context of the thread or in the caller thread when + * the loop is not running. Since 0.3.3 */ +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); + #ifdef __cplusplus } #endif