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

@ -86,7 +86,7 @@ static void stream_link(struct group *group, struct stream *stream)
struct modify_info info = { .stream = stream, .streams = &group->streams };
int res;
res = spa_loop_invoke(group->data_loop, do_modify, 0, NULL, 0, true, &info);
res = spa_loop_locked(group->data_loop, do_modify, 0, NULL, 0, &info);
spa_assert_se(res == 0);
}
@ -95,7 +95,7 @@ static void stream_unlink(struct stream *stream)
struct modify_info info = { .stream = stream, .streams = NULL };
int res;
res = spa_loop_invoke(stream->group->data_loop, do_modify, 0, NULL, 0, true, &info);
res = spa_loop_locked(stream->group->data_loop, do_modify, 0, NULL, 0, &info);
spa_assert_se(res == 0);
}
@ -393,7 +393,7 @@ static void group_destroy(struct group *group)
spa_assert(spa_list_is_empty(&group->streams));
res = spa_loop_invoke(group->data_loop, do_remove_source, 0, NULL, 0, true, group);
res = spa_loop_locked(group->data_loop, do_remove_source, 0, NULL, 0, group);
spa_assert_se(res == 0);
close(group->timerfd);

View file

@ -452,7 +452,7 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
}
if (this->started) {
spa_loop_invoke(this->data_loop, do_reassign_io, 0, NULL, 0, true, &info);
spa_loop_locked(this->data_loop, do_reassign_io, 0, NULL, 0, &info);
} else {
this->clock = info.clock;
this->position = info.position;
@ -1548,7 +1548,7 @@ static int transport_start(struct impl *this)
this->transport_started = true;
if (this->transport->iso_io)
spa_loop_invoke(this->data_loop, do_start_iso_io, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_start_iso_io, 0, NULL, 0, this);
if (is_asha) {
struct spa_bt_asha *asha = this->asha;
@ -1678,7 +1678,7 @@ static void transport_stop(struct impl *this)
spa_log_trace(this->log, "%p: stop transport", this);
spa_loop_invoke(this->data_loop, do_remove_transport_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_transport_source, 0, NULL, 0, this);
if (this->codec_data && this->own_codec_data)
this->codec->deinit(this->codec_data);
@ -1696,7 +1696,7 @@ static int do_stop(struct impl *this)
this->start_ready = false;
spa_loop_invoke(this->data_loop, do_remove_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_source, 0, NULL, 0, this);
transport_stop(this);
@ -2310,7 +2310,7 @@ static void transport_destroy(void *data)
{
struct impl *this = data;
spa_log_debug(this->log, "transport %p destroy", this->transport);
spa_loop_invoke(this->data_loop, do_transport_destroy, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_transport_destroy, 0, NULL, 0, this);
}
static void transport_state_changed(void *data,

View file

@ -315,7 +315,7 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
if (this->started && following != this->following) {
spa_log_debug(this->log, "%p: reassign follower %d->%d", this, this->following, following);
this->following = following;
spa_loop_invoke(this->data_loop, do_reassign_follower, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_reassign_follower, 0, NULL, 0, this);
}
return 0;
}
@ -799,7 +799,7 @@ static int transport_start(struct impl *this)
spa_strerror(res));
if (this->transport->iso_io)
spa_loop_invoke(this->data_loop, do_start_iso_io, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_start_iso_io, 0, NULL, 0, this);
this->transport_started = true;
@ -899,7 +899,7 @@ static void transport_stop(struct impl *this)
spa_log_debug(this->log, "%p: transport stop", this);
spa_loop_invoke(this->data_loop, do_remove_transport_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_transport_source, 0, NULL, 0, this);
if (this->fd >= 0) {
close(this->fd);
@ -924,7 +924,7 @@ static int do_stop(struct impl *this)
this->start_ready = false;
spa_loop_invoke(this->data_loop, do_remove_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_source, 0, NULL, 0, this);
transport_stop(this);
@ -1736,7 +1736,7 @@ static void transport_destroy(void *data)
{
struct impl *this = data;
spa_log_debug(this->log, "transport %p destroy", this->transport);
spa_loop_invoke(this->data_loop, do_transport_destroy, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_transport_destroy, 0, NULL, 0, this);
}
static const struct spa_bt_transport_events transport_events = {

View file

@ -1135,7 +1135,7 @@ static int do_stop(struct impl *this)
spa_log_debug(this->log, "%p: stop", this);
spa_loop_invoke(this->data_loop, do_remove_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_source, 0, NULL, 0, this);
this->started = false;
@ -1149,7 +1149,7 @@ static int do_release(struct impl *this)
spa_log_debug(this->log, "%p: release", this);
spa_loop_invoke(this->data_loop, do_remove_port_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_port_source, 0, NULL, 0, this);
for (i = 0; i < N_PORTS; ++i) {
struct port *port = &this->ports[i];
@ -1260,7 +1260,7 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
if (this->started && following != this->following) {
spa_log_debug(this->log, "%p: reassign follower %d->%d", this, this->following, following);
this->following = following;
spa_loop_invoke(this->data_loop, do_reassign_follower, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_reassign_follower, 0, NULL, 0, this);
}
return 0;

View file

@ -271,7 +271,7 @@ static int do_remove_source(struct spa_loop *loop,
void spa_bt_sco_io_destroy(struct spa_bt_sco_io *io)
{
if (io->started)
spa_loop_invoke(io->data_loop, do_remove_source, 0, NULL, 0, true, io);
spa_loop_locked(io->data_loop, do_remove_source, 0, NULL, 0, io);
io->started = false;
free(io);

View file

@ -308,7 +308,7 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
if (this->started && following != this->following) {
spa_log_debug(this->log, "%p: reassign follower %d->%d", this, this->following, following);
this->following = following;
spa_loop_invoke(this->data_loop, do_reassign_follower, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_reassign_follower, 0, NULL, 0, this);
}
return 0;
}
@ -954,7 +954,7 @@ static void transport_stop(struct impl *this)
spa_log_trace(this->log, "sco-sink %p: transport stop", this);
spa_loop_invoke(this->data_loop, do_remove_transport_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_transport_source, 0, NULL, 0, this);
if (this->buffer) {
free(this->buffer);
@ -978,7 +978,7 @@ static int do_stop(struct impl *this)
this->start_ready = false;
spa_loop_invoke(this->data_loop, do_remove_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_source, 0, NULL, 0, this);
transport_stop(this);
@ -1571,7 +1571,7 @@ static void transport_destroy(void *data)
{
struct impl *this = data;
spa_log_debug(this->log, "transport %p destroy", this->transport);
spa_loop_invoke(this->data_loop, do_transport_destroy, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_transport_destroy, 0, NULL, 0, this);
}
static const struct spa_bt_transport_events transport_events = {

View file

@ -285,7 +285,7 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
if (this->started && following != this->following) {
spa_log_debug(this->log, "%p: reassign follower %d->%d", this, this->following, following);
this->following = following;
spa_loop_invoke(this->data_loop, do_reassign_follower, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_reassign_follower, 0, NULL, 0, this);
}
return 0;
@ -764,7 +764,7 @@ static int transport_start(struct impl *this)
/* Start socket i/o */
if ((res = spa_bt_transport_ensure_sco_io(this->transport, this->data_loop, this->data_system)) < 0)
goto fail;
spa_loop_invoke(this->data_loop, do_add_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_add_source, 0, NULL, 0, this);
/* Set the started flag */
this->transport_started = true;
@ -862,7 +862,7 @@ static void transport_stop(struct impl *this)
spa_log_debug(this->log, "sco-source %p: transport stop", this);
spa_loop_invoke(this->data_loop, do_remove_transport_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_transport_source, 0, NULL, 0, this);
spa_bt_decode_buffer_clear(&port->buffer);
@ -882,7 +882,7 @@ static int do_stop(struct impl *this)
this->start_ready = false;
spa_loop_invoke(this->data_loop, do_remove_source, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_source, 0, NULL, 0, this);
transport_stop(this);
@ -1589,7 +1589,7 @@ static void transport_destroy(void *data)
{
struct impl *this = data;
spa_log_debug(this->log, "transport %p destroy", this->transport);
spa_loop_invoke(this->data_loop, do_transport_destroy, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_transport_destroy, 0, NULL, 0, this);
}
static const struct spa_bt_transport_events transport_events = {

View file

@ -262,7 +262,7 @@ static void spatializer_reload(void * Instance)
spa_log_error(impl->log, "reloading left or right convolver failed");
return;
}
spa_loop_invoke(impl->plugin->data_loop, do_switch, 1, NULL, 0, true, impl);
spa_loop_locked(impl->plugin->data_loop, do_switch, 1, NULL, 0, impl);
}
struct free_data {

View file

@ -1059,7 +1059,7 @@ static int spa_libcamera_stream_off(struct impl *impl)
impl->camera->requestCompleted.disconnect(impl, &impl::requestComplete);
spa_loop_invoke(impl->data_loop, do_remove_source, 0, NULL, 0, true, impl);
spa_loop_locked(impl->data_loop, do_remove_source, 0, NULL, 0, impl);
if (impl->source.fd >= 0) {
spa_system_close(impl->system, impl->source.fd);
impl->source.fd = -1;

View file

@ -708,7 +708,7 @@ static int impl_clear(struct spa_handle *handle)
this = (struct impl *) handle;
if (this->data_loop)
spa_loop_invoke(this->data_loop, do_remove_timer, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_timer, 0, NULL, 0, this);
spa_system_close(this->data_system, this->timer_source.fd);
return 0;

View file

@ -739,7 +739,7 @@ static int impl_clear(struct spa_handle *handle)
this = (struct impl *) handle;
if (this->data_loop)
spa_loop_invoke(this->data_loop, do_remove_timer, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_timer, 0, NULL, 0, this);
spa_system_close(this->data_system, this->timer_source.fd);
return 0;

View file

@ -2220,7 +2220,7 @@ impl_node_port_set_io(void *object,
case SPA_IO_Buffers:
if (this->data_loop) {
struct io_data d = { .port = port, .data = data, .size = size };
spa_loop_invoke(this->data_loop, do_set_port_io, 0, NULL, 0, true, &d);
spa_loop_locked(this->data_loop, do_set_port_io, 0, NULL, 0, &d);
}
else
port->io = data;

View file

@ -852,7 +852,7 @@ static int impl_clear(struct spa_handle *handle)
this = (struct impl *) handle;
if (this->data_loop)
spa_loop_invoke(this->data_loop, do_remove_timer, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_timer, 0, NULL, 0, this);
spa_loop_utils_destroy_source(this->loop_utils, this->timer_source);
return 0;

View file

@ -933,7 +933,7 @@ static int impl_clear(struct spa_handle *handle)
spa_vulkan_compute_deinit(&this->state);
if (this->data_loop)
spa_loop_invoke(this->data_loop, do_remove_timer, 0, NULL, 0, true, this);
spa_loop_locked(this->data_loop, do_remove_timer, 0, NULL, 0, this);
spa_system_close(this->data_system, this->timer_source.fd);
return 0;