[pulseaudio-commits] r2491 - in /trunk/src/pulsecore: hashmap.c hashmap.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu May 29 08:16:59 PDT 2008


Author: lennart
Date: Thu May 29 17:16:58 2008
New Revision: 2491

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2491&root=pulseaudio&view=rev
Log:
allow on-the-fly deleting of hashmap entries wile we iterate through them

Modified:
    trunk/src/pulsecore/hashmap.c
    trunk/src/pulsecore/hashmap.h

Modified: trunk/src/pulsecore/hashmap.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/hashmap.c?rev=2491&root=pulseaudio&r1=2490&r2=2491&view=diff
==============================================================================
--- trunk/src/pulsecore/hashmap.c (original)
+++ trunk/src/pulsecore/hashmap.c Thu May 29 17:16:58 2008
@@ -191,24 +191,36 @@
 }
 
 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;
+    if (*state == (void*) -1)
+        goto at_end;
+
+    if ((!*state && !h->first_entry))
+        goto at_end;
+
+    e = *state ? *state : h->first_entry;
+
+    if (e->next)
+        *state = e->next;
     else
-        *state = ((struct hashmap_entry*) *state)->next;
-
-    if (!*state) {
-        if (key)
-            *key = NULL;
-        return NULL;
-    }
+        *state = (void*) -1;
 
     if (key)
-        *key = ((struct hashmap_entry*) *state)->key;
-
-    return ((struct hashmap_entry*) *state)->value;
+        *key = e->key;
+
+    return e->value;
+
+at_end:
+    *state = (void *) -1;
+
+    if (key)
+        *key = NULL;
+
+    return NULL;
 }
 
 void* pa_hashmap_steal_first(pa_hashmap *h) {

Modified: trunk/src/pulsecore/hashmap.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/hashmap.h?rev=2491&root=pulseaudio&r1=2490&r2=2491&view=diff
==============================================================================
--- trunk/src/pulsecore/hashmap.h (original)
+++ trunk/src/pulsecore/hashmap.h Thu May 29 17:16:58 2008
@@ -51,9 +51,10 @@
 
 /* May be used to iterate through the hashmap. Initially the opaque
    pointer *state has to be set to NULL. The hashmap may not be
-   modified during iteration. The key of the entry is returned in
-   *key, if key is non-NULL. After the last entry in the hashmap NULL
-   is returned. */
+   modified during iteration -- except for deleting the current entry
+   via pa_hashmap_remove(). The key of the entry is returned in *key,
+   if key is non-NULL. After the last entry in the hashmap NULL is
+   returned. */
 void *pa_hashmap_iterate(pa_hashmap *h, void **state, const void**key);
 
 void *pa_hashmap_steal_first(pa_hashmap *h);




More information about the pulseaudio-commits mailing list