aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-03-17 08:20:34 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-03-17 08:20:34 -0400
commit7a7dff5186fa1b96f15c82672fc94432196d7eb5 (patch)
treeebed190c4ae52d8fd62c27550645b2e671409624
parent77a0f70e491da2a26323d24b4c1d65320996c469 (diff)
downloadlibrambutan-7a7dff5186fa1b96f15c82672fc94432196d7eb5.tar.gz
librambutan-7a7dff5186fa1b96f15c82672fc94432196d7eb5.zip
Adding rb_safe_remove() to ring_buffer.h
-rw-r--r--libmaple/ring_buffer.h11
1 files changed, 11 insertions, 0 deletions
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
@@ -79,6 +79,17 @@ static inline uint8 rb_remove(ring_buffer *rb) {
}
/**
+ * 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. */
static inline int rb_safe_insert(ring_buffer *rb, uint8 element) {