diff options
-rw-r--r-- | common/ring.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/common/ring.h b/common/ring.h index defa1eda..a013a2fa 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 |