From b626a8520618e94d228278ea4359279afae28665 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Mon, 29 Oct 2012 20:34:52 +0100 Subject: [PATCH] shl: ring: add shl_ring_flush() helper This helper flushes all messages from the ring buffer and releases the memory. Signed-off-by: David Herrmann --- src/shl_ring.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/shl_ring.h b/src/shl_ring.h index 5e6622f..bd346f6 100644 --- a/src/shl_ring.h +++ b/src/shl_ring.h @@ -184,4 +184,19 @@ next: } } +static inline void shl_ring_flush(struct shl_ring *ring) +{ + struct shl_ring_entry *tmp; + + if (!ring) + return; + + while (ring->first) { + tmp = ring->first; + ring->first = tmp->next; + free(tmp); + } + ring->last = NULL; +} + #endif /* SHL_RING_H */