summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTanu Kaskinen <tanuk@iki.fi>2013-02-12 21:36:57 +0200
committerTanu Kaskinen <tanuk@iki.fi>2013-02-16 01:18:59 +0200
commit2c666e3e166b2992f114325e3ec53f28f98738df (patch)
treeb83a8c28492e80c16e3c47fe64041d7fccc8fcc7 /src
parent31ee1a7d54f6ba6eb96a9ae38ad9dfda72c67673 (diff)
idxset: Add pa_idxset_remove_all()
Slightly nicer than using pa_idxset_steal_first() in a loop.
Diffstat (limited to 'src')
-rw-r--r--src/modules/alsa/module-alsa-card.c16
-rw-r--r--src/pulsecore/core-scache.c5
-rw-r--r--src/pulsecore/idxset.c23
-rw-r--r--src/pulsecore/idxset.h3
-rw-r--r--src/pulsecore/module.c4
-rw-r--r--src/pulsecore/protocol-dbus.c11
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 3c995f8f2..3f5af34a3 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 73f65d2c8..64bc4b3d0 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 fc3ea58c8..27e4980dc 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 0b12ac1b7..039e4be13 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 bf554af0e..f63c9cdd0 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 bda234617..17ad902e4 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);
}
}