[Spice-devel] [PATCH 04/26] ring: add RING_FOREACH{, _SAFE, _REVERSED}

Alon Levy alevy at redhat.com
Fri Feb 11 09:48:49 PST 2011


---
 common/ring.h |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/common/ring.h b/common/ring.h
index defa1ed..a841422 100644
--- a/common/ring.h
+++ b/common/ring.h
@@ -129,5 +129,24 @@ static inline RingItem *ring_prev(Ring *ring, RingItem *pos)
     return (ret == ring) ? NULL : ret;
 }
 
+#define RING_FOREACH_SAFE(var, next, ring)                    \
+    for ((var) = ring_get_head(ring),                         \
+         (next) = (var) ? ring_next(ring, (var)) : NULL;      \
+            (var);                                            \
+            (var) = (next),                                   \
+            (next) = (var) ? ring_next(ring, (var)) : NULL)
+
+
+#define RING_FOREACH(var, ring)                 \
+    for ((var) = ring_get_head(ring);           \
+            (var);                              \
+            (var) = ring_next(ring, var))
+
+#define RING_FOREACH_REVERSED(var, ring)        \
+    for ((var) = ring_get_tail(ring);           \
+            (var);                              \
+            (var) = ring_prev(ring, var))
+
+
 #endif
 
-- 
1.7.4



More information about the Spice-devel mailing list