From 7a7dff5186fa1b96f15c82672fc94432196d7eb5 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Thu, 17 Mar 2011 08:20:34 -0400 Subject: Adding rb_safe_remove() to ring_buffer.h --- libmaple/ring_buffer.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libmaple/ring_buffer.h b/libmaple/ring_buffer.h index f7baa6c..6e9b250 100644 --- a/libmaple/ring_buffer.h +++ b/libmaple/ring_buffer.h @@ -78,6 +78,17 @@ static inline uint8 rb_remove(ring_buffer *rb) { return ch; } +/** + * If the ring buffer is nonempty, removes and returns its first item. + * If it is empty, does nothing and returns a negative value. + */ +static inline int16 rb_safe_remove(ring_buffer *rb) { + if (rb_full_count(rb) == 0) { + return -1; + } + return rb_remove(rb); +} + /** * If rb is not full, appends element and returns true; otherwise, * does nothing and returns false. */ -- cgit v1.2.3