Slightly nicer than using pa_hashmap_steal_first() in a loop.
mixer_handle = pa_alsa_open_mixer_for_pcm(pcm_handle, NULL, &hctl_handle);
if (!mixer_handle || !hctl_handle) {
/* Cannot open mixer, remove all entries */
- while (pa_hashmap_steal_first(ps->paths));
+ pa_hashmap_remove_all(ps->paths, NULL);
return;
}
free(sessions);
}
- while ((o = pa_hashmap_steal_first(u->previous_sessions)))
- free_session(o);
+ pa_hashmap_remove_all(u->previous_sessions, (pa_free_cb_t) free_session);
return 0;
}
}
void pa_proplist_clear(pa_proplist *p) {
- struct property *prop;
pa_assert(p);
- while ((prop = pa_hashmap_steal_first(MAKE_HASHMAP(p))))
- property_free(prop);
+ pa_hashmap_remove_all(MAKE_HASHMAP(p), (pa_free_cb_t) property_free);
}
pa_proplist* pa_proplist_copy(const pa_proplist *p) {
int pa_database_clear(pa_database *database) {
simple_data *db = (simple_data*)database;
- entry *e;
pa_assert(db);
- while ((e = pa_hashmap_steal_first(db->map)))
- free_entry(e);
+ pa_hashmap_remove_all(db->map, (pa_free_cb_t) free_entry);
return 0;
}
void pa_hashmap_free(pa_hashmap *h, pa_free_cb_t free_cb) {
pa_assert(h);
- while (h->iterate_list_head) {
- void *data;
- data = h->iterate_list_head->value;
- remove_entry(h, h->iterate_list_head);
-
- if (free_cb)
- free_cb(data);
- }
-
+ pa_hashmap_remove_all(h, free_cb);
pa_xfree(h);
}
return data;
}
+void pa_hashmap_remove_all(pa_hashmap *h, pa_free_cb_t free_cb) {
+ pa_assert(h);
+
+ while (h->iterate_list_head) {
+ void *data;
+ data = h->iterate_list_head->value;
+ remove_entry(h, h->iterate_list_head);
+
+ if (free_cb)
+ free_cb(data);
+ }
+}
+
void *pa_hashmap_iterate(pa_hashmap *h, void **state, const void **key) {
struct hashmap_entry *e;
/* Returns the data of the entry while removing */
void* pa_hashmap_remove(pa_hashmap *h, const void *key);
+/* If free_cb is not NULL, it's called for each entry. */
+void pa_hashmap_remove_all(pa_hashmap *h, pa_free_cb_t free_cb);
+
/* Return the current number of entries of the hashmap */
unsigned pa_hashmap_size(pa_hashmap *h);
/* We're not interested in individual signals anymore, so let's empty
* listening_signals. */
- while ((signal_paths_entry = pa_hashmap_steal_first(conn_entry->listening_signals)))
- signal_paths_entry_free(signal_paths_entry);
+ pa_hashmap_remove_all(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
for (i = 0; i < n_objects; ++i)
pa_idxset_put(conn_entry->all_signals_objects, pa_xstrdup(objects[i]), NULL);
while ((object_path = pa_idxset_steal_first(conn_entry->all_signals_objects, NULL)))
pa_xfree(object_path);
- while ((signal_paths_entry = pa_hashmap_steal_first(conn_entry->listening_signals)))
- signal_paths_entry_free(signal_paths_entry);
+ pa_hashmap_remove_all(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
}
}