idxset: Add pa_idxset_remove_all()

Slightly nicer than using pa_idxset_steal_first() in a loop.
This commit is contained in:
Tanu Kaskinen 2013-02-12 21:36:57 +02:00
parent 31ee1a7d54
commit 2c666e3e16
6 changed files with 25 additions and 37 deletions

View 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);

View 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);

View 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;

View 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 =

View 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);

View 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);
}
}