loop: spa_loop_invoke -> spa_loop_locked where possible

When we simply need to change some state for the code executed in the
loop, we can use locked() instead of invoke(). This is more efficient
and avoids some context switches in the normal case.
This commit is contained in:
Wim Taymans 2025-05-30 11:59:35 +02:00
parent b943c31fd8
commit c45d667934
29 changed files with 75 additions and 75 deletions

View file

@ -87,7 +87,7 @@ bool client_detach(struct client *client)
if (server->wait_clients > 0 && --server->wait_clients == 0) {
int mask = server->source->mask;
SPA_FLAG_SET(mask, SPA_IO_IN);
pw_loop_update_io(impl->loop, server->source, mask);
pw_loop_update_io(impl->main_loop, server->source, mask);
}
client->server = NULL;
@ -112,7 +112,7 @@ void client_disconnect(struct client *client)
pw_map_for_each(&client->streams, client_free_stream, client);
if (client->source) {
pw_loop_destroy_source(impl->loop, client->source);
pw_loop_destroy_source(impl->main_loop, client->source);
client->source = NULL;
}
@ -207,7 +207,7 @@ int client_queue_message(struct client *client, struct message *msg)
uint32_t mask = client->source->mask;
if (!SPA_FLAG_IS_SET(mask, SPA_IO_OUT)) {
SPA_FLAG_SET(mask, SPA_IO_OUT);
pw_loop_update_io(impl->loop, client->source, mask);
pw_loop_update_io(impl->main_loop, client->source, mask);
}
client->new_msg_since_last_flush = true;
@ -278,7 +278,7 @@ int client_flush_messages(struct client *client)
if (SPA_FLAG_IS_SET(mask, SPA_IO_OUT)) {
SPA_FLAG_CLEAR(mask, SPA_IO_OUT);
pw_loop_update_io(client->impl->loop, client->source, mask);
pw_loop_update_io(client->impl->main_loop, client->source, mask);
}
} else {
if (res != -EAGAIN && res != -EWOULDBLOCK)

View file

@ -47,7 +47,7 @@ struct stats {
};
struct impl {
struct pw_loop *loop;
struct pw_loop *main_loop;
struct pw_context *context;
struct spa_hook context_listener;

View file

@ -214,12 +214,12 @@ static int module_combine_sink_load(struct module *module)
pw_manager_add_listener(data->manager, &data->manager_listener,
&manager_events, data);
data->sinks_timeout = pw_loop_add_timer(module->impl->loop, on_sinks_timeout, data);
data->sinks_timeout = pw_loop_add_timer(module->impl->main_loop, on_sinks_timeout, data);
if (data->sinks_timeout) {
struct timespec timeout = {0};
timeout.tv_sec = TIMEOUT_SINKS_MSEC / 1000;
timeout.tv_nsec = (TIMEOUT_SINKS_MSEC % 1000) * SPA_NSEC_PER_MSEC;
pw_loop_update_timer(module->impl->loop, data->sinks_timeout, &timeout, NULL, false);
pw_loop_update_timer(module->impl->main_loop, data->sinks_timeout, &timeout, NULL, false);
}
return data->load_emitted ? 0 : SPA_RESULT_RETURN_ASYNC(0);
}
@ -229,7 +229,7 @@ static int module_combine_sink_unload(struct module *module)
struct module_combine_sink_data *d = module->user_data;
if (d->sinks_timeout != NULL)
pw_loop_destroy_source(module->impl->loop, d->sinks_timeout);
pw_loop_destroy_source(module->impl->main_loop, d->sinks_timeout);
if (d->mod != NULL) {
spa_hook_remove(&d->mod_listener);

View file

@ -197,7 +197,7 @@ static void handle_module_group(struct module_gsettings_data *d, gchar *name)
snprintf(p, sizeof(p), "args%i", i);
info.args[i] = g_settings_get_string(settings, p);
}
pw_loop_invoke(impl->loop, do_handle_info, 0,
pw_loop_invoke(impl->main_loop, do_handle_info, 0,
&info, sizeof(info), false, d);
g_object_unref(G_OBJECT(settings));

View file

@ -1484,7 +1484,7 @@ static void stream_process(void *data)
pw_stream_get_time_n(stream->stream, &pd.pwt, sizeof(pd.pwt));
pw_loop_invoke(impl->loop,
pw_loop_invoke(impl->main_loop,
do_process_done, 1, &pd, sizeof(pd), false, stream);
}
@ -5492,7 +5492,7 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context,
spa_list_init(&impl->cleanup_clients);
spa_list_init(&impl->free_messages);
impl->loop = pw_context_get_main_loop(context);
impl->main_loop = pw_context_get_main_loop(context);
impl->work_queue = pw_context_get_work_queue(context);
if (props == NULL)

View file

@ -384,7 +384,7 @@ on_connect(void *data, int fd, uint32_t mask)
if (server->n_clients > 0) {
int m = server->source->mask;
SPA_FLAG_CLEAR(m, SPA_IO_IN);
pw_loop_update_io(impl->loop, server->source, m);
pw_loop_update_io(impl->main_loop, server->source, m);
server->wait_clients++;
}
}
@ -404,7 +404,7 @@ on_connect(void *data, int fd, uint32_t mask)
pw_log_debug("server %p: new client %p fd:%d", server, client, client_fd);
client->source = pw_loop_add_io(impl->loop,
client->source = pw_loop_add_io(impl->main_loop,
client_fd,
SPA_IO_ERR | SPA_IO_HUP | SPA_IO_IN,
true, on_client_data, client);
@ -949,7 +949,7 @@ static int server_start(struct server *server, const struct sockaddr_storage *ad
if (fd < 0)
return fd;
server->source = pw_loop_add_io(impl->loop, fd, SPA_IO_IN, true, on_connect, server);
server->source = pw_loop_add_io(impl->main_loop, fd, SPA_IO_IN, true, on_connect, server);
if (server->source == NULL) {
res = -errno;
pw_log_error("server %p: can't create server source: %m", impl);
@ -1100,7 +1100,7 @@ void server_free(struct server *server)
spa_hook_list_call(&impl->hooks, struct impl_events, server_stopped, 0, server);
if (server->source)
pw_loop_destroy_source(impl->loop, server->source);
pw_loop_destroy_source(impl->main_loop, server->source);
if (server->addr.ss_family == AF_UNIX && !server->activated)
unlink(((const struct sockaddr_un *) &server->addr)->sun_path);

View file

@ -118,7 +118,7 @@ void stream_free(struct stream *stream)
/* force processing of all pending messages before we destroy
* the stream */
pw_loop_invoke(impl->loop, NULL, 0, NULL, 0, false, client);
pw_loop_invoke(impl->main_loop, NULL, 0, NULL, 0, false, client);
pw_stream_destroy(stream->stream);
}