[pulseaudio-discuss] [PATCH 07/13] idxset: Add pa_idxset_remove_all()
Tanu Kaskinen
tanuk at iki.fi
Tue Feb 12 11:36:57 PST 2013
Slightly nicer than using pa_idxset_steal_first() in a loop.
---
src/modules/alsa/module-alsa-card.c | 16 ++++------------
src/pulsecore/core-scache.c | 5 +----
src/pulsecore/idxset.c | 23 ++++++++++++++---------
src/pulsecore/idxset.h | 3 +++
src/pulsecore/module.c | 4 +---
src/pulsecore/protocol-dbus.c | 11 ++---------
6 files changed, 25 insertions(+), 37 deletions(-)
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index 3c995f8..3f5af34 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -746,19 +746,11 @@ void pa__done(pa_module*m) {
if (u->jacks)
pa_hashmap_free(u->jacks, NULL);
- if (u->card && u->card->sinks) {
- pa_sink *s;
+ if (u->card && u->card->sinks)
+ pa_idxset_remove_all(u->card->sinks, (pa_free_cb_t) pa_alsa_sink_free);
- while ((s = pa_idxset_steal_first(u->card->sinks, NULL)))
- pa_alsa_sink_free(s);
- }
-
- if (u->card && u->card->sources) {
- pa_source *s;
-
- while ((s = pa_idxset_steal_first(u->card->sources, NULL)))
- pa_alsa_source_free(s);
- }
+ if (u->card && u->card->sources)
+ pa_idxset_remove_all(u->card->sources, (pa_free_cb_t) pa_alsa_source_free);
if (u->card)
pa_card_free(u->card);
diff --git a/src/pulsecore/core-scache.c b/src/pulsecore/core-scache.c
index 73f65d2..64bc4b3 100644
--- a/src/pulsecore/core-scache.c
+++ b/src/pulsecore/core-scache.c
@@ -282,12 +282,9 @@ int pa_scache_remove_item(pa_core *c, const char *name) {
}
void pa_scache_free_all(pa_core *c) {
- pa_scache_entry *e;
-
pa_assert(c);
- while ((e = pa_idxset_steal_first(c->scache, NULL)))
- free_entry(e);
+ pa_idxset_remove_all(c->scache, (pa_free_cb_t) free_entry);
if (c->scache_auto_unload_event) {
c->mainloop->time_free(c->scache_auto_unload_event);
diff --git a/src/pulsecore/idxset.c b/src/pulsecore/idxset.c
index fc3ea58..27e4980 100644
--- a/src/pulsecore/idxset.c
+++ b/src/pulsecore/idxset.c
@@ -142,15 +142,7 @@ static void remove_entry(pa_idxset *s, struct idxset_entry *e) {
void pa_idxset_free(pa_idxset *s, pa_free_cb_t free_cb) {
pa_assert(s);
- while (s->iterate_list_head) {
- void *data = s->iterate_list_head->data;
-
- remove_entry(s, s->iterate_list_head);
-
- if (free_cb)
- free_cb(data);
- }
-
+ pa_idxset_remove_all(s, free_cb);
pa_xfree(s);
}
@@ -308,6 +300,19 @@ void* pa_idxset_remove_by_data(pa_idxset*s, const void *data, uint32_t *idx) {
return r;
}
+void pa_idxset_remove_all(pa_idxset *s, pa_free_cb_t free_cb) {
+ pa_assert(s);
+
+ while (s->iterate_list_head) {
+ void *data = s->iterate_list_head->data;
+
+ remove_entry(s, s->iterate_list_head);
+
+ if (free_cb)
+ free_cb(data);
+ }
+}
+
void* pa_idxset_rrobin(pa_idxset *s, uint32_t *idx) {
unsigned hash;
struct idxset_entry *e;
diff --git a/src/pulsecore/idxset.h b/src/pulsecore/idxset.h
index 0b12ac1..039e4be 100644
--- a/src/pulsecore/idxset.h
+++ b/src/pulsecore/idxset.h
@@ -73,6 +73,9 @@ void* pa_idxset_remove_by_index(pa_idxset*s, uint32_t idx);
/* Similar to pa_idxset_get_by_data(), but removes the entry from the idxset */
void* pa_idxset_remove_by_data(pa_idxset*s, const void *p, uint32_t *idx);
+/* If free_cb is not NULL, it's called for each entry. */
+void pa_idxset_remove_all(pa_idxset *s, pa_free_cb_t free_cb);
+
/* This may be used to iterate through all entries. When called with
an invalid index value it returns the first entry, otherwise the
next following. The function is best called with *idx =
diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c
index bf554af..f63c9cd 100644
--- a/src/pulsecore/module.c
+++ b/src/pulsecore/module.c
@@ -203,11 +203,9 @@ void pa_module_unload_by_index(pa_core *c, uint32_t idx, pa_bool_t force) {
}
void pa_module_unload_all(pa_core *c) {
- pa_module *m;
pa_assert(c);
- while ((m = pa_idxset_steal_first(c->modules, NULL)))
- pa_module_free(m);
+ pa_idxset_remove_all(c->modules, (pa_free_cb_t) pa_module_free);
if (c->module_defer_unload_event) {
c->mainloop->defer_free(c->module_defer_unload_event);
diff --git a/src/pulsecore/protocol-dbus.c b/src/pulsecore/protocol-dbus.c
index bda2346..17ad902 100644
--- a/src/pulsecore/protocol-dbus.c
+++ b/src/pulsecore/protocol-dbus.c
@@ -974,7 +974,6 @@ void pa_dbus_protocol_add_signal_listener(
unsigned n_objects) {
struct connection_entry *conn_entry = NULL;
struct signal_paths_entry *signal_paths_entry = NULL;
- char *object_path = NULL;
unsigned i = 0;
pa_assert(p);
@@ -986,8 +985,7 @@ void pa_dbus_protocol_add_signal_listener(
/* all_signals_objects will either be emptied or replaced with new objects,
* so we empty it here unconditionally. If listening_for_all_signals is
* currently FALSE, the idxset is empty already so this does nothing. */
- while ((object_path = pa_idxset_steal_first(conn_entry->all_signals_objects, NULL)))
- pa_xfree(object_path);
+ pa_idxset_remove_all(conn_entry->all_signals_objects, pa_xfree);
if (signal_name) {
conn_entry->listening_for_all_signals = FALSE;
@@ -1029,13 +1027,8 @@ void pa_dbus_protocol_remove_signal_listener(pa_dbus_protocol *p, DBusConnection
signal_paths_entry_free(signal_paths_entry);
} else {
- char *object_path;
-
conn_entry->listening_for_all_signals = FALSE;
-
- while ((object_path = pa_idxset_steal_first(conn_entry->all_signals_objects, NULL)))
- pa_xfree(object_path);
-
+ pa_idxset_remove_all(conn_entry->all_signals_objects, pa_xfree);
pa_hashmap_remove_all(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
}
}
--
1.7.10.4
More information about the pulseaudio-discuss
mailing list