aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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) {