[Spice-devel] [PATCH v2 21/40] ring: add RING_FOREACH{, _SAFE, _REVERSED}

Alon Levy alevy at redhat.com
Wed Mar 2 00:31:44 PST 2011


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

diff --git a/common/ring.h b/common/ring.h
index defa1ed..a013a2f 100644
--- a/common/ring.h
+++ b/common/ring.h
@@ -19,6 +19,8 @@
 #ifndef _H_RING2
 #define _H_RING2
 
+#include "spice_common.h"
+
 typedef struct Ring RingItem;
 typedef struct Ring {
     RingItem *prev;
@@ -129,5 +131,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.1



More information about the Spice-devel mailing list