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.
This commit is contained in:
Wim Taymans 2020-04-30 11:54:15 +02:00
parent 5e99e7da49
commit cec26494f8
2 changed files with 19 additions and 0 deletions

View file

@ -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;
}

View file

@ -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