mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
allow on-the-fly deleting of hashmap entries wile we iterate through them
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2491 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
c4f60d5960
commit
8431fb17c2
2 changed files with 27 additions and 14 deletions
|
|
@ -191,24 +191,36 @@ unsigned pa_hashmap_size(pa_hashmap *h) {
|
|||
}
|
||||
|
||||
void *pa_hashmap_iterate(pa_hashmap *h, void **state, const void **key) {
|
||||
struct hashmap_entry *e;
|
||||
|
||||
pa_assert(h);
|
||||
pa_assert(state);
|
||||
|
||||
if (!*state)
|
||||
*state = h->first_entry;
|
||||
else
|
||||
*state = ((struct hashmap_entry*) *state)->next;
|
||||
if (*state == (void*) -1)
|
||||
goto at_end;
|
||||
|
||||
if (!*state) {
|
||||
if (key)
|
||||
*key = NULL;
|
||||
return NULL;
|
||||
}
|
||||
if ((!*state && !h->first_entry))
|
||||
goto at_end;
|
||||
|
||||
e = *state ? *state : h->first_entry;
|
||||
|
||||
if (e->next)
|
||||
*state = e->next;
|
||||
else
|
||||
*state = (void*) -1;
|
||||
|
||||
if (key)
|
||||
*key = ((struct hashmap_entry*) *state)->key;
|
||||
*key = e->key;
|
||||
|
||||
return ((struct hashmap_entry*) *state)->value;
|
||||
return e->value;
|
||||
|
||||
at_end:
|
||||
*state = (void *) -1;
|
||||
|
||||
if (key)
|
||||
*key = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* pa_hashmap_steal_first(pa_hashmap *h) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue