From bc164814cc6e218618eefe39a66a6336a13b3b0c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 13 Jan 2022 16:35:48 +0100 Subject: [PATCH] context: improve retry logic Remove the useless retry logic and fail when we wrapped around while scanning for an unused id. --- src/pipewire/context.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pipewire/context.c b/src/pipewire/context.c index f77b2a029..6caa619be 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -592,13 +592,13 @@ static struct pw_global *find_global(struct pw_context *context, uint32_t id) static uint32_t next_global_id(struct pw_context *context) { - uint32_t id, retry = 0; - + uint32_t id, start = context->serial; while (true) { - id = context->serial++ & 0xffffff; + id = context->serial; + context->serial = (context->serial+1) & 0xffffff; if (find_global(context, id) == NULL) return id; - if (retry++ > 4096) + if (context->serial == start) break; } return SPA_ID_INVALID; @@ -608,6 +608,7 @@ uint32_t pw_context_add_global(struct pw_context *context, struct pw_global *glo { global->id = next_global_id(context); spa_list_append(&context->global_list, &global->link); + return global->id; } void pw_context_remove_global(struct pw_context *context, struct pw_global *global)