diff options
| author | Marti Bolivar <mbolivar@leaflabs.com> | 2011-03-17 08:20:34 -0400 |
|---|---|---|
| committer | Marti Bolivar <mbolivar@leaflabs.com> | 2011-03-17 08:20:34 -0400 |
| commit | 8097736f3be70ed3a5550334b31e8cfeddc0bfcf (patch) | |
| tree | f4d27c415ab73d66f964d04f8c341e9bcbce00d1 /libmaple/ring_buffer.h | |
| parent | 54f2f41142c9393c7df1b92ec0941a82d8f2ffc6 (diff) | |
Adding rb_safe_remove() to ring_buffer.h
Diffstat (limited to 'libmaple/ring_buffer.h')
| -rw-r--r-- | libmaple/ring_buffer.h | 11 |
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) { |
