diff options
author | Tanu Kaskinen <tanu.kaskinen@linux.intel.com> | 2014-03-26 17:39:47 +0200 |
---|---|---|
committer | Tanu Kaskinen <tanu.kaskinen@linux.intel.com> | 2014-04-17 10:02:42 +0300 |
commit | 14e2553185e1afa93737586771326cd12a154239 (patch) | |
tree | 933c56d48bfb42e1292366e634310044e365e30e /src/pulsecore | |
parent | 36f775482f2e54e7de0b00ead980c6617e88bad3 (diff) |
hashmap: Add pa_hashmap_remove_and_free()
Diffstat (limited to 'src/pulsecore')
-rw-r--r-- | src/pulsecore/hashmap.c | 13 | ||||
-rw-r--r-- | src/pulsecore/hashmap.h | 7 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/pulsecore/hashmap.c b/src/pulsecore/hashmap.c index acac1e06a..2cc03cbab 100644 --- a/src/pulsecore/hashmap.c +++ b/src/pulsecore/hashmap.c @@ -207,6 +207,19 @@ void* pa_hashmap_remove(pa_hashmap *h, const void *key) { return data; } +int pa_hashmap_remove_and_free(pa_hashmap *h, const void *key) { + void *data; + + pa_assert(h); + + data = pa_hashmap_remove(h, key); + + if (data && h->value_free_func) + h->value_free_func(data); + + return data ? 0 : -1; +} + void pa_hashmap_remove_all(pa_hashmap *h) { pa_assert(h); diff --git a/src/pulsecore/hashmap.h b/src/pulsecore/hashmap.h index e42732ae9..8042f7bd9 100644 --- a/src/pulsecore/hashmap.h +++ b/src/pulsecore/hashmap.h @@ -52,6 +52,13 @@ 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); +/* Removes the entry and frees the entry data. Returns a negative value if the + * entry is not found. FIXME: This function shouldn't be needed. + * pa_hashmap_remove() should free the entry data, and the current semantics of + * pa_hashmap_remove() should be implemented by a function called + * pa_hashmap_steal(). */ +int pa_hashmap_remove_and_free(pa_hashmap *h, const void *key); + /* Remove all entries but don't free the hashmap */ void pa_hashmap_remove_all(pa_hashmap *h); |