core: improve cleanup

When the core is disconnected, first do _remove on all active
proxies and then run the _destroy handles. This makes it easier
to clean up dependent resources.

Remove the modules after removing all objects. It's harder for
 odules to track and remove all objects.
This commit is contained in:
Wim Taymans 2020-06-03 15:38:13 +02:00
parent 4405fe4c14
commit a7225090c8
3 changed files with 23 additions and 7 deletions

View file

@ -358,9 +358,6 @@ void pw_context_destroy(struct pw_context *context)
spa_list_consume(core, &context->core_list, link)
pw_core_disconnect(core);
spa_list_consume(module, &context->module_list, link)
pw_impl_module_destroy(module);
spa_list_consume(node, &context->node_list, link)
pw_impl_node_destroy(node);
@ -370,6 +367,9 @@ void pw_context_destroy(struct pw_context *context)
spa_list_consume(resource, &context->registry_resource_list, link)
pw_resource_destroy(resource);
spa_list_consume(module, &context->module_list, link)
pw_impl_module_destroy(module);
spa_list_consume(global, &context->global_list, link)
pw_global_destroy(global);

View file

@ -181,18 +181,18 @@ static int remove_proxy(void *object, void *data)
return 0;
}
static void proxy_core_destroy(void *data)
static void proxy_core_removed(void *data)
{
struct pw_core *core = data;
struct pw_stream *stream, *s2;
struct pw_filter *filter, *f2;
if (core->destroyed)
if (core->removed)
return;
core->destroyed = true;
core->removed = true;
pw_log_debug(NAME" %p: core proxy destroy", core);
pw_log_debug(NAME" %p: core proxy removed", core);
spa_list_remove(&core->link);
spa_list_for_each_safe(stream, s2, &core->stream_list, link)
@ -202,6 +202,20 @@ static void proxy_core_destroy(void *data)
pw_map_for_each(&core->objects, remove_proxy, core);
pw_map_reset(&core->objects);
}
static void proxy_core_destroy(void *data)
{
struct pw_core *core = data;
struct pw_stream *stream;
struct pw_filter *filter;
if (core->destroyed)
return;
core->destroyed = true;
pw_log_debug(NAME" %p: core proxy destroy", core);
spa_list_consume(stream, &core->stream_list, link)
pw_stream_destroy(stream);
@ -223,6 +237,7 @@ static void proxy_core_destroy(void *data)
static const struct pw_proxy_events proxy_core_events = {
PW_VERSION_PROXY_EVENTS,
.removed = proxy_core_removed,
.destroy = proxy_core_destroy,
};

View file

@ -840,6 +840,7 @@ struct pw_core {
int recv_seq; /**< last received sequence number */
int send_seq; /**< last protocol result code */
unsigned int removed:1;
unsigned int destroyed:1;
void *user_data; /**< extra user data */