thread: deprecate pw_thread_utils_set()

Setting a global thread-utils is not a good idea, especially
when multiple contexts will register their own interface.

Instead, set the thread-utils as a context object and use this to
configure the data loop in the context.

In JACK we need a per context implementation of the interface so that
we can find the context specific thread-utils.

See #2252
This commit is contained in:
Wim Taymans 2022-03-30 20:31:42 +02:00
parent f3466f8cd6
commit f0424c0b99
6 changed files with 59 additions and 33 deletions

View file

@ -464,8 +464,7 @@ finish:
static void module_destroy(void *data)
{
struct impl *impl = data;
pw_thread_utils_set(NULL);
pw_context_set_object(impl->context, SPA_TYPE_INTERFACE_ThreadUtils, NULL);
spa_hook_remove(&impl->module_listener);
#ifdef HAVE_DBUS
@ -931,7 +930,9 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
SPA_TYPE_INTERFACE_ThreadUtils,
SPA_VERSION_THREAD_UTILS,
&impl_thread_utils, impl);
pw_thread_utils_set(&impl->thread_utils);
pw_context_set_object(context, SPA_TYPE_INTERFACE_ThreadUtils,
&impl->thread_utils);
pw_impl_module_add_listener(module, &impl->module_listener, &module_events, impl);

View file

@ -124,18 +124,20 @@ static int try_load_conf(struct pw_context *this, const char *conf_prefix,
static int context_set_freewheel(struct pw_context *context, bool freewheel)
{
struct spa_thread *thr;
int res;
int res = 0;
if ((thr = pw_data_loop_get_thread(context->data_loop_impl)) == NULL)
return -EIO;
if (freewheel) {
pw_log_info("%p: enter freewheel", context);
res = pw_thread_utils_drop_rt(thr);
if (context->thread_utils)
res = spa_thread_utils_drop_rt(context->thread_utils, thr);
} else {
pw_log_info("%p: exit freewheel", context);
// Use the priority as configured within the realtime module
res = pw_thread_utils_acquire_rt(thr, -1);
/* Use the priority as configured within the realtime module */
if (context->thread_utils)
res = spa_thread_utils_acquire_rt(context->thread_utils, thr, -1);
}
if (res < 0)
pw_log_info("%p: freewheel error:%s", context, spa_strerror(res));
@ -1455,6 +1457,12 @@ int pw_context_set_object(struct pw_context *context, const char *type, void *va
}
entry->value = value;
}
if (spa_streq(type, SPA_TYPE_INTERFACE_ThreadUtils)) {
context->thread_utils = value;
if (context->data_loop_impl)
pw_data_loop_set_thread_utils(context->data_loop_impl,
context->thread_utils);
}
return 0;
}

View file

@ -455,6 +455,7 @@ struct pw_context {
struct spa_hook_list driver_listener_list;
struct spa_hook_list listener_list;
struct spa_thread_utils *thread_utils;
struct pw_loop *main_loop; /**< main loop for control */
struct pw_loop *data_loop; /**< data loop for data passing */
struct pw_data_loop *data_loop_impl;

View file

@ -83,9 +83,7 @@ static struct spa_thread_utils *global_impl = &default_impl.utils;
SPA_EXPORT
void pw_thread_utils_set(struct spa_thread_utils *impl)
{
if (impl == NULL)
impl = &default_impl.utils;
global_impl = impl;
pw_log_warn("pw_thread_utils_set is deprecated and does nothing anymore");
}
SPA_EXPORT

View file

@ -44,6 +44,7 @@ extern "C" {
* \{
*/
SPA_DEPRECATED
void pw_thread_utils_set(struct spa_thread_utils *impl);
struct spa_thread_utils *pw_thread_utils_get(void);