]> code.delx.au - pulseaudio/commitdiff
idxset: Add pa_idxset_remove_all()
authorTanu Kaskinen <tanuk@iki.fi>
Tue, 12 Feb 2013 19:36:57 +0000 (21:36 +0200)
committerTanu Kaskinen <tanuk@iki.fi>
Fri, 15 Feb 2013 23:18:59 +0000 (01:18 +0200)
Slightly nicer than using pa_idxset_steal_first() in a loop.

src/modules/alsa/module-alsa-card.c
src/pulsecore/core-scache.c
src/pulsecore/idxset.c
src/pulsecore/idxset.h
src/pulsecore/module.c
src/pulsecore/protocol-dbus.c

index 3c995f8f2529e8e726e53810818a6ccb721fa3e3..3f5af34a3bc1d0ac27f8a21c89a9a04671bdafaf 100644 (file)
@@ -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);
index 73f65d2c8afd139e015a7c95dd8145752ac9655e..64bc4b3d0c3ef8cd78bd218669bd4b500dc0f7fe 100644 (file)
@@ -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);
index fc3ea58c8db6bde7d656043adde883417d115753..27e4980dce83ce5edda97747e29f46f91c150167 100644 (file)
@@ -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;
index 0b12ac1b7e05260c5021cdfeb98b16dec0828451..039e4be133cc463d7f30f0b391a516ccc71c6889 100644 (file)
@@ -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 =
index bf554af0e8a59ec668b672c0649f203fba129ff2..f63c9cdd0b3c2914a605ed4b0c95cb5dd35eff0a 100644 (file)
@@ -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);
index bda234617e92d6541b18beddc02ba249da3d6687..17ad902e4e1b10f792591f63a3b1c434cf446b6d 100644 (file)
@@ -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);
     }
 }