From 92ef2cd56bb859e7fa266145e9eea2bcc9819e11 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 14 Jan 2022 20:01:21 +0100 Subject: [PATCH] Revert "context: implement faster id collision check" This reverts commit 8ca037683ef5585a6d8501c8a34d7ceea797f088. --- src/pipewire/context.c | 43 +++++++++++++++--------------------------- src/pipewire/core.h | 3 --- src/pipewire/private.h | 2 -- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/pipewire/context.c b/src/pipewire/context.c index 040e23184..f473177f7 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -221,7 +221,6 @@ struct pw_context *pw_context_new(struct pw_loop *main_loop, spa_list_init(&this->core_list); spa_list_init(&this->registry_resource_list); spa_list_init(&this->global_list); - spa_list_init(&this->sorted_globals); spa_list_init(&this->module_list); spa_list_init(&this->device_list); spa_list_init(&this->client_list); @@ -592,34 +591,23 @@ static struct pw_global *find_global(struct pw_context *context, uint32_t id) return NULL; } +static uint32_t next_global_id(struct pw_context *context) +{ + uint32_t id, start = context->serial; + while (true) { + id = context->serial; + context->serial = (context->serial+1) & 0xffffff; + if (find_global(context, id) == NULL) + return id; + if (context->serial == start) + break; + } + return SPA_ID_INVALID; +} + uint32_t pw_context_add_global(struct pw_context *context, struct pw_global *global) { - uint32_t count = 0; - - while (true) { - struct pw_global *g; - - if (spa_list_is_empty(&context->sorted_globals)) - break; - - g = spa_list_first(&context->sorted_globals, struct pw_global, sorted_link); - if (g->id != context->serial) - break; - context->serial = (context->serial+1) & PW_ID_MASK; - - /* we have found a global with the next serial, move it to the back - * of the sorted list */ - spa_list_remove(&g->sorted_link); - spa_list_append(&context->sorted_globals, &g->sorted_link); - - /* if we tried PW_ID_MASK times, we're out of ids */ - if (++count == PW_ID_MASK) - return SPA_ID_INVALID; - } - global->id = context->serial; - context->serial = (context->serial+1) & PW_ID_MASK; - - spa_list_append(&context->sorted_globals, &global->sorted_link); + global->id = next_global_id(context); spa_list_append(&context->global_list, &global->link); return global->id; } @@ -627,7 +615,6 @@ uint32_t pw_context_add_global(struct pw_context *context, struct pw_global *glo void pw_context_remove_global(struct pw_context *context, struct pw_global *global) { spa_list_remove(&global->link); - spa_list_remove(&global->sorted_link); } SPA_EXPORT diff --git a/src/pipewire/core.h b/src/pipewire/core.h index f6cc0884e..5995b36dd 100644 --- a/src/pipewire/core.h +++ b/src/pipewire/core.h @@ -68,9 +68,6 @@ struct pw_registry; /* invalid ID that matches any object when used for permissions */ #define PW_ID_ANY (uint32_t)(0xffffffff) -/* ID will only use these bits */ -#define PW_ID_MASK (uint32_t)(0xffffff) - /** The core information. Extra information may be added in later versions, * clients must not assume a constant struct size */ struct pw_core_info { diff --git a/src/pipewire/private.h b/src/pipewire/private.h index 6f706e4f6..1c5751e44 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -320,7 +320,6 @@ struct pw_global { struct pw_context *context; /**< the context */ struct spa_list link; /**< link in context list of globals */ - struct spa_list sorted_link; /**< link in context list of sorted_globals */ uint32_t id; /**< server id of the object */ struct pw_properties *properties; /**< properties of the global */ @@ -452,7 +451,6 @@ struct pw_context { struct pw_array factory_lib; /**< mapping of factory_name regexp to library */ uint32_t serial; - struct spa_list sorted_globals; struct pw_array objects; /**< objects */ struct pw_impl_client *current_client; /**< client currently executing code in mainloop */