diff options
Diffstat (limited to 'src/pulsecore')
-rw-r--r-- | src/pulsecore/database-simple.c | 4 | ||||
-rw-r--r-- | src/pulsecore/hashmap.c | 23 | ||||
-rw-r--r-- | src/pulsecore/hashmap.h | 3 | ||||
-rw-r--r-- | src/pulsecore/protocol-dbus.c | 6 |
4 files changed, 20 insertions, 16 deletions
diff --git a/src/pulsecore/database-simple.c b/src/pulsecore/database-simple.c index 5dd3ac9b6..91c1b4570 100644 --- a/src/pulsecore/database-simple.c +++ b/src/pulsecore/database-simple.c @@ -339,12 +339,10 @@ int pa_database_unset(pa_database *database, const pa_datum *key) { 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; } diff --git a/src/pulsecore/hashmap.c b/src/pulsecore/hashmap.c index cfd08b7a1..3e1d9f147 100644 --- a/src/pulsecore/hashmap.c +++ b/src/pulsecore/hashmap.c @@ -104,15 +104,7 @@ static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) { 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); } @@ -202,6 +194,19 @@ void* pa_hashmap_remove(pa_hashmap *h, const void *key) { 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; diff --git a/src/pulsecore/hashmap.h b/src/pulsecore/hashmap.h index 8d892b8ff..59ff12ead 100644 --- a/src/pulsecore/hashmap.h +++ b/src/pulsecore/hashmap.h @@ -48,6 +48,9 @@ void* pa_hashmap_get(pa_hashmap *h, const void *key); /* 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); diff --git a/src/pulsecore/protocol-dbus.c b/src/pulsecore/protocol-dbus.c index ffd8ea203..bda234617 100644 --- a/src/pulsecore/protocol-dbus.c +++ b/src/pulsecore/protocol-dbus.c @@ -1008,8 +1008,7 @@ void pa_dbus_protocol_add_signal_listener( /* 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); @@ -1037,8 +1036,7 @@ void pa_dbus_protocol_remove_signal_listener(pa_dbus_protocol *p, DBusConnection 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); } } |