Slightly nicer than using pa_idxset_steal_first() in a loop.
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);
}
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);
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);
}
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;
/* 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 =
}
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);
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);
/* 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;
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);
}
}