mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
context: hash the globals by id
Store the globals by id in a hashtable. O(1) insert and remove. It moves the find_global overhead from the top of the list to somewhere in the middle for the jack-stress test.
This commit is contained in:
parent
6394537dbd
commit
80b2e345d7
2 changed files with 13 additions and 2 deletions
|
|
@ -198,6 +198,7 @@ struct pw_context *pw_context_new(struct pw_loop *main_loop,
|
||||||
struct pw_properties *pr, *conf;
|
struct pw_properties *pr, *conf;
|
||||||
struct spa_cpu *cpu;
|
struct spa_cpu *cpu;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
struct spa_list *m;
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
impl = calloc(1, sizeof(struct impl) + user_data_size);
|
||||||
if (impl == NULL) {
|
if (impl == NULL) {
|
||||||
|
|
@ -215,6 +216,9 @@ struct pw_context *pw_context_new(struct pw_loop *main_loop,
|
||||||
pw_array_init(&this->factory_lib, 32);
|
pw_array_init(&this->factory_lib, 32);
|
||||||
pw_array_init(&this->objects, 32);
|
pw_array_init(&this->objects, 32);
|
||||||
|
|
||||||
|
SPA_FOR_EACH_ELEMENT(this->global_map, m)
|
||||||
|
spa_list_init(m);
|
||||||
|
|
||||||
spa_list_init(&this->core_impl_list);
|
spa_list_init(&this->core_impl_list);
|
||||||
spa_list_init(&this->protocol_list);
|
spa_list_init(&this->protocol_list);
|
||||||
spa_list_init(&this->core_list);
|
spa_list_init(&this->core_list);
|
||||||
|
|
@ -479,7 +483,6 @@ void pw_context_destroy(struct pw_context *context)
|
||||||
free(entry->lib);
|
free(entry->lib);
|
||||||
}
|
}
|
||||||
pw_array_clear(&context->factory_lib);
|
pw_array_clear(&context->factory_lib);
|
||||||
|
|
||||||
pw_array_clear(&context->objects);
|
pw_array_clear(&context->objects);
|
||||||
|
|
||||||
spa_hook_list_clean(&context->listener_list);
|
spa_hook_list_clean(&context->listener_list);
|
||||||
|
|
@ -584,7 +587,10 @@ int pw_context_for_each_global(struct pw_context *context,
|
||||||
static struct pw_global *find_global(struct pw_context *context, uint32_t id)
|
static struct pw_global *find_global(struct pw_context *context, uint32_t id)
|
||||||
{
|
{
|
||||||
struct pw_global *g;
|
struct pw_global *g;
|
||||||
spa_list_for_each(g, &context->global_list, link) {
|
struct spa_list *l;
|
||||||
|
|
||||||
|
l = &context->global_map[id % GLOBAL_HASH_SIZE];
|
||||||
|
spa_list_for_each(g, l, map_link) {
|
||||||
if (g->id == id)
|
if (g->id == id)
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
@ -618,6 +624,7 @@ uint32_t pw_context_add_global(struct pw_context *context, struct pw_global *glo
|
||||||
global->id = context->serial;
|
global->id = context->serial;
|
||||||
context->serial = (context->serial+1) & PW_ID_MASK;
|
context->serial = (context->serial+1) & PW_ID_MASK;
|
||||||
|
|
||||||
|
spa_list_prepend(&context->global_map[global->id % GLOBAL_HASH_SIZE], &global->map_link);
|
||||||
spa_list_append(&context->sorted_globals, &global->sorted_link);
|
spa_list_append(&context->sorted_globals, &global->sorted_link);
|
||||||
spa_list_append(&context->global_list, &global->link);
|
spa_list_append(&context->global_list, &global->link);
|
||||||
return global->id;
|
return global->id;
|
||||||
|
|
@ -627,6 +634,7 @@ void pw_context_remove_global(struct pw_context *context, struct pw_global *glob
|
||||||
{
|
{
|
||||||
spa_list_remove(&global->link);
|
spa_list_remove(&global->link);
|
||||||
spa_list_remove(&global->sorted_link);
|
spa_list_remove(&global->sorted_link);
|
||||||
|
spa_list_remove(&global->map_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
|
|
|
||||||
|
|
@ -321,6 +321,7 @@ struct pw_global {
|
||||||
|
|
||||||
struct spa_list link; /**< link in context list of globals */
|
struct spa_list link; /**< link in context list of globals */
|
||||||
struct spa_list sorted_link; /**< link in context list of sorted_globals */
|
struct spa_list sorted_link; /**< link in context list of sorted_globals */
|
||||||
|
struct spa_list map_link; /**< link in context list of global_map */
|
||||||
uint32_t id; /**< server id of the object */
|
uint32_t id; /**< server id of the object */
|
||||||
|
|
||||||
struct pw_properties *properties; /**< properties of the global */
|
struct pw_properties *properties; /**< properties of the global */
|
||||||
|
|
@ -452,6 +453,8 @@ struct pw_context {
|
||||||
struct pw_array factory_lib; /**< mapping of factory_name regexp to library */
|
struct pw_array factory_lib; /**< mapping of factory_name regexp to library */
|
||||||
|
|
||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
|
#define GLOBAL_HASH_SIZE 127
|
||||||
|
struct spa_list global_map[GLOBAL_HASH_SIZE];
|
||||||
struct spa_list sorted_globals;
|
struct spa_list sorted_globals;
|
||||||
struct pw_array objects; /**< objects */
|
struct pw_array objects; /**< objects */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue