Revert "context: implement faster id collision check"

This reverts commit 8ca037683e.
This commit is contained in:
Wim Taymans 2022-01-14 20:01:21 +01:00
parent 1f58b147d6
commit 92ef2cd56b
3 changed files with 15 additions and 33 deletions

View file

@ -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;
}
uint32_t pw_context_add_global(struct pw_context *context, struct pw_global *global)
static uint32_t next_global_id(struct pw_context *context)
{
uint32_t count = 0;
uint32_t id, start = context->serial;
while (true) {
struct pw_global *g;
if (spa_list_is_empty(&context->sorted_globals))
id = context->serial;
context->serial = (context->serial+1) & 0xffffff;
if (find_global(context, id) == NULL)
return id;
if (context->serial == start)
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);
uint32_t pw_context_add_global(struct pw_context *context, struct pw_global *global)
{
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

View file

@ -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 {

View file

@ -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 */