summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2019-05-06 17:04:16 +0200
committerWim Taymans <wtaymans@redhat.com>2019-05-06 17:04:16 +0200
commit2b5c6fd6769edc70253bc40ce1a627afe1dce500 (patch)
treecfa3b8115089230d1331b127e45097d34702c409
parentfa0b4f9321a3952af96ae8b63a882e9a9133cd35 (diff)
list: add _consume method
Add safer way to destroy a list of objects.
-rw-r--r--spa/include/spa/utils/list.h5
-rw-r--r--spa/plugins/support/loop.c4
-rw-r--r--src/modules/module-protocol-native.c4
-rw-r--r--src/pipewire/client.c6
-rw-r--r--src/pipewire/core.c16
-rw-r--r--src/pipewire/link.c6
-rw-r--r--src/pipewire/module.c4
-rw-r--r--src/pipewire/node.c10
-rw-r--r--src/pipewire/port.c10
-rw-r--r--src/pipewire/protocol.c8
-rw-r--r--src/pipewire/remote.c8
11 files changed, 43 insertions, 38 deletions
diff --git a/spa/include/spa/utils/list.h b/spa/include/spa/utils/list.h
index 18a06a52..523fbae9 100644
--- a/spa/include/spa/utils/list.h
+++ b/spa/include/spa/utils/list.h
@@ -78,6 +78,11 @@ static inline void spa_list_remove(struct spa_list *elem)
#define spa_list_next(pos, member) \
SPA_CONTAINER_OF((pos)->member.next, __typeof__(*pos), member)
+#define spa_list_consume(pos, head, member) \
+ for (pos = spa_list_first(head, __typeof__(*pos), member); \
+ !spa_list_is_empty(head); \
+ pos = spa_list_first(head, __typeof__(*pos), member))
+
#define spa_list_for_each_next(pos, head, curr, member) \
for (pos = spa_list_first(curr, __typeof__(*pos), member); \
!spa_list_is_end(pos, head, member); \
diff --git a/spa/plugins/support/loop.c b/spa/plugins/support/loop.c
index 1c770a16..941a7505 100644
--- a/spa/plugins/support/loop.c
+++ b/spa/plugins/support/loop.c
@@ -686,13 +686,13 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
static int impl_clear(struct spa_handle *handle)
{
struct impl *impl;
- struct source_impl *source, *tmp;
+ struct source_impl *source;
spa_return_val_if_fail(handle != NULL, -EINVAL);
impl = (struct impl *) handle;
- spa_list_for_each_safe(source, tmp, &impl->source_list, link)
+ spa_list_consume(source, &impl->source_list, link)
loop_destroy_source(&source->source);
process_destroy(impl);
diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c
index c00fb163..4929fc6d 100644
--- a/src/modules/module-protocol-native.c
+++ b/src/modules/module-protocol-native.c
@@ -716,11 +716,11 @@ impl_new_client(struct pw_protocol *protocol,
static void destroy_server(struct pw_protocol_server *server)
{
struct server *s = SPA_CONTAINER_OF(server, struct server, this);
- struct pw_client *client, *tmp;
+ struct pw_client *client;
spa_list_remove(&server->link);
- spa_list_for_each_safe(client, tmp, &server->client_list, protocol_link)
+ spa_list_consume(client, &server->client_list, protocol_link)
pw_client_destroy(client);
if (s->source)
diff --git a/src/pipewire/client.c b/src/pipewire/client.c
index 2730c3d0..8259db2a 100644
--- a/src/pipewire/client.c
+++ b/src/pipewire/client.c
@@ -105,7 +105,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions,
data = pw_resource_get_user_data(resource);
pw_resource_add_listener(resource, &data->resource_listener, &resource_events, resource);
- pw_log_debug("client %p: bound to %d", this, resource->id);
+ pw_log_debug("client %p: bound to %p %d", this, resource, resource->id);
spa_list_append(&this->resource_list, &resource->link);
@@ -305,7 +305,7 @@ static int destroy_resource(void *object, void *data)
SPA_EXPORT
void pw_client_destroy(struct pw_client *client)
{
- struct pw_resource *resource, *tmp;
+ struct pw_resource *resource;
struct impl *impl = SPA_CONTAINER_OF(client, struct impl, this);
pw_log_debug("client %p: destroy", client);
@@ -321,7 +321,7 @@ void pw_client_destroy(struct pw_client *client)
pw_global_destroy(client->global);
}
- spa_list_for_each_safe(resource, tmp, &client->resource_list, link)
+ spa_list_consume(resource, &client->resource_list, link)
pw_resource_destroy(resource);
pw_map_for_each(&client->objects, destroy_resource, client);
diff --git a/src/pipewire/core.c b/src/pipewire/core.c
index 7c74b2a4..c0bf0278 100644
--- a/src/pipewire/core.c
+++ b/src/pipewire/core.c
@@ -473,26 +473,26 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, struct pw_properties *pro
SPA_EXPORT
void pw_core_destroy(struct pw_core *core)
{
- struct pw_global *global, *t;
- struct pw_module *module, *tm;
- struct pw_remote *remote, *tr;
- struct pw_node *node, *tn;
+ struct pw_global *global;
+ struct pw_module *module;
+ struct pw_remote *remote;
+ struct pw_node *node;
pw_log_debug("core %p: destroy", core);
pw_core_events_destroy(core);
spa_hook_remove(&core->global_listener);
- spa_list_for_each_safe(remote, tr, &core->remote_list, link)
+ spa_list_consume(remote, &core->remote_list, link)
pw_remote_destroy(remote);
- spa_list_for_each_safe(module, tm, &core->module_list, link)
+ spa_list_consume(module, &core->module_list, link)
pw_module_destroy(module);
- spa_list_for_each_safe(node, tn, &core->node_list, link)
+ spa_list_consume(node, &core->node_list, link)
pw_node_destroy(node);
- spa_list_for_each_safe(global, t, &core->global_list, link)
+ spa_list_consume(global, &core->global_list, link)
pw_global_destroy(global);
pw_core_events_free(core);
diff --git a/src/pipewire/link.c b/src/pipewire/link.c
index fcea7535..b352f289 100644
--- a/src/pipewire/link.c
+++ b/src/pipewire/link.c
@@ -1278,7 +1278,7 @@ SPA_EXPORT
void pw_link_destroy(struct pw_link *link)
{
struct impl *impl = SPA_CONTAINER_OF(link, struct impl, this);
- struct pw_resource *resource, *tmp;
+ struct pw_resource *resource;
pw_log_debug("link %p: destroy", impl);
pw_link_events_destroy(link);
@@ -1300,8 +1300,8 @@ void pw_link_destroy(struct pw_link *link)
pw_global_destroy(link->global);
}
- spa_list_for_each_safe(resource, tmp, &link->resource_list, link)
- pw_resource_destroy(resource);
+ spa_list_consume(resource, &link->resource_list, link)
+ pw_resource_destroy(resource);
pw_log_debug("link %p: free", impl);
pw_link_events_free(link);
diff --git a/src/pipewire/module.c b/src/pipewire/module.c
index de069a0c..da4173ea 100644
--- a/src/pipewire/module.c
+++ b/src/pipewire/module.c
@@ -287,7 +287,7 @@ SPA_EXPORT
void pw_module_destroy(struct pw_module *module)
{
struct impl *impl = SPA_CONTAINER_OF(module, struct impl, this);
- struct pw_resource *resource, *tmp;
+ struct pw_resource *resource;
pw_log_debug("module %p: destroy", module);
pw_module_events_destroy(module);
@@ -298,7 +298,7 @@ void pw_module_destroy(struct pw_module *module)
spa_hook_remove(&module->global_listener);
pw_global_destroy(module->global);
}
- spa_list_for_each_safe(resource, tmp, &module->resource_list, link)
+ spa_list_consume(resource, &module->resource_list, link)
pw_resource_destroy(resource);
free((char *) module->info.name);
diff --git a/src/pipewire/node.c b/src/pipewire/node.c
index 24f5cbb7..81725e2d 100644
--- a/src/pipewire/node.c
+++ b/src/pipewire/node.c
@@ -624,8 +624,8 @@ SPA_EXPORT
void pw_node_destroy(struct pw_node *node)
{
struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this);
- struct pw_resource *resource, *tmp;
- struct pw_port *port, *tmpp;
+ struct pw_resource *resource;
+ struct pw_port *port;
pw_log_debug("node %p: destroy", impl);
pw_node_events_destroy(node);
@@ -642,11 +642,11 @@ void pw_node_destroy(struct pw_node *node)
pw_port_unlink(port);
pw_log_debug("node %p: destroy ports", node);
- spa_list_for_each_safe(port, tmpp, &node->input_ports, link) {
+ spa_list_consume(port, &node->input_ports, link) {
pw_node_events_port_removed(node, port);
pw_port_destroy(port);
}
- spa_list_for_each_safe(port, tmpp, &node->output_ports, link) {
+ spa_list_consume(port, &node->output_ports, link) {
pw_node_events_port_removed(node, port);
pw_port_destroy(port);
}
@@ -655,7 +655,7 @@ void pw_node_destroy(struct pw_node *node)
spa_hook_remove(&node->global_listener);
pw_global_destroy(node->global);
}
- spa_list_for_each_safe(resource, tmp, &node->resource_list, link)
+ spa_list_consume(resource, &node->resource_list, link)
pw_resource_destroy(resource);
pw_log_debug("node %p: free", node);
diff --git a/src/pipewire/port.c b/src/pipewire/port.c
index 3a9b268d..ab4642c3 100644
--- a/src/pipewire/port.c
+++ b/src/pipewire/port.c
@@ -542,8 +542,8 @@ static void pw_port_remove(struct pw_port *port)
void pw_port_destroy(struct pw_port *port)
{
struct pw_node *node = port->node;
- struct pw_control *control, *ctemp;
- struct pw_resource *resource, *tmp;
+ struct pw_control *control;
+ struct pw_resource *resource;
pw_log_debug("port %p: destroy", port);
@@ -552,16 +552,16 @@ void pw_port_destroy(struct pw_port *port)
if (node)
pw_port_remove(port);
- spa_list_for_each_safe(control, ctemp, &port->control_list[0], port_link)
+ spa_list_consume(control, &port->control_list[0], port_link)
pw_control_destroy(control);
- spa_list_for_each_safe(control, ctemp, &port->control_list[1], port_link)
+ spa_list_consume(control, &port->control_list[1], port_link)
pw_control_destroy(control);
if (port->global) {
spa_hook_remove(&port->global_listener);
pw_global_destroy(port->global);
}
- spa_list_for_each_safe(resource, tmp, &port->resource_list, link)
+ spa_list_consume(resource, &port->resource_list, link)
pw_resource_destroy(resource);
pw_log_debug("port %p: free", port);
diff --git a/src/pipewire/protocol.c b/src/pipewire/protocol.c
index da1004c7..93adc6a5 100644
--- a/src/pipewire/protocol.c
+++ b/src/pipewire/protocol.c
@@ -88,18 +88,18 @@ void pw_protocol_destroy(struct pw_protocol *protocol)
{
struct impl *impl = SPA_CONTAINER_OF(protocol, struct impl, this);
struct marshal *marshal, *t1;
- struct pw_protocol_server *server, *t2;
- struct pw_protocol_client *client, *t3;
+ struct pw_protocol_server *server;
+ struct pw_protocol_client *client;
pw_log_debug("protocol %p: destroy", protocol);
pw_protocol_events_destroy(protocol);
spa_list_remove(&protocol->link);
- spa_list_for_each_safe(server, t2, &protocol->server_list, link)
+ spa_list_consume(server, &protocol->server_list, link)
pw_protocol_server_destroy(server);
- spa_list_for_each_safe(client, t3, &protocol->client_list, link)
+ spa_list_consume(client, &protocol->client_list, link)
pw_protocol_client_destroy(client);
spa_list_for_each_safe(marshal, t1, &protocol->marshal_list, link)
diff --git a/src/pipewire/remote.c b/src/pipewire/remote.c
index 9887fcba..544c77b6 100644
--- a/src/pipewire/remote.c
+++ b/src/pipewire/remote.c
@@ -292,7 +292,7 @@ SPA_EXPORT
void pw_remote_destroy(struct pw_remote *remote)
{
struct remote *impl = SPA_CONTAINER_OF(remote, struct remote, this);
- struct pw_stream *stream, *s2;
+ struct pw_stream *stream;
pw_log_debug("remote %p: destroy", remote);
pw_remote_events_destroy(remote);
@@ -300,7 +300,7 @@ void pw_remote_destroy(struct pw_remote *remote)
if (remote->state != PW_REMOTE_STATE_UNCONNECTED)
pw_remote_disconnect(remote);
- spa_list_for_each_safe(stream, s2, &remote->stream_list, link)
+ spa_list_consume(stream, &remote->stream_list, link)
pw_stream_destroy(stream);
pw_protocol_client_destroy (remote->conn);
@@ -449,14 +449,14 @@ int pw_remote_steal_fd(struct pw_remote *remote)
SPA_EXPORT
int pw_remote_disconnect(struct pw_remote *remote)
{
- struct pw_proxy *proxy, *t2;
+ struct pw_proxy *proxy;
struct pw_stream *stream, *s2;
pw_log_debug("remote %p: disconnect", remote);
spa_list_for_each_safe(stream, s2, &remote->stream_list, link)
pw_stream_disconnect(stream);
- spa_list_for_each_safe(proxy, t2, &remote->proxy_list, link)
+ spa_list_consume(proxy, &remote->proxy_list, link)
pw_proxy_destroy(proxy);
remote->core_proxy = NULL;