global: avoid using existing global id

Add the global immediately after creating it. Make sure we only
enumerate registered globals. This way, we can already check for
duplicate ids before the global is registered.

When allocating a global id, avoid using an existing id. Move some
code around to make it easier to implement a more efficient algorithm
for collision detection.

Move the object id counter to the context.
This commit is contained in:
Wim Taymans 2022-01-13 16:10:35 +01:00
parent 3a49168f26
commit 5baab24848
3 changed files with 34 additions and 6 deletions

View file

@ -450,6 +450,7 @@ struct pw_context {
uint32_t n_support; /**< number of support items */
struct pw_array factory_lib; /**< mapping of factory_name regexp to library */
uint32_t serial;
struct pw_array objects; /**< objects */
struct pw_impl_client *current_client; /**< client currently executing code in mainloop */
@ -1115,6 +1116,9 @@ struct pw_control {
void *user_data;
};
uint32_t pw_context_add_global(struct pw_context *context, struct pw_global *global);
void pw_context_remove_global(struct pw_context *context, struct pw_global *global);
/** Find a good format between 2 ports */
int pw_context_find_format(struct pw_context *context,
struct pw_impl_port *output,