From 8452e6d28e4aeac61b344f2a0e7f29a78000c94e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 5 May 2023 17:43:27 +0200 Subject: [PATCH] data-loop: optimize iterate dispatch Avoid doing the interface unref and version check for each iteration but do this before entering the loop. Improves performance in high frequency wakeups. --- src/pipewire/data-loop.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pipewire/data-loop.c b/src/pipewire/data-loop.c index d9341fcb6..1ea4563e0 100644 --- a/src/pipewire/data-loop.c +++ b/src/pipewire/data-loop.c @@ -51,6 +51,18 @@ static void *do_loop(void *user_data) { struct pw_data_loop *this = user_data; int res; + int (*iterate) (void *object, int timeout); + struct spa_interface *iface = &this->loop->control->iface; + struct spa_callbacks *cb = &iface->cb; + const struct spa_loop_control_methods *m = + (const struct spa_loop_control_methods *)cb->funcs; + void *data = cb->data; + + if (!SPA_CALLBACK_CHECK(m, iterate, 0)) { + pw_log_error("loop is missing iterate method"); + return NULL; + } + iterate = m->iterate; pw_log_debug("%p: enter thread", this); pw_loop_enter(this->loop); @@ -58,7 +70,7 @@ static void *do_loop(void *user_data) pthread_cleanup_push(thread_cleanup, this); while (SPA_LIKELY(this->running)) { - if (SPA_UNLIKELY((res = pw_loop_iterate(this->loop, -1)) < 0)) { + if (SPA_UNLIKELY((res = iterate(data, -1)) < 0)) { if (res == -EINTR) continue; pw_log_error("%p: iterate error %d (%s)",