|
|
@ -57,25 +57,25 @@ RingBuffer::~RingBuffer() |
|
|
|
unsigned |
|
|
|
unsigned |
|
|
|
RingBuffer::_next(unsigned index) |
|
|
|
RingBuffer::_next(unsigned index) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return (0 == index) ? _num_items : (index - 1);
|
|
|
|
return (0 == index) ? _num_items : (index - 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
bool |
|
|
|
RingBuffer::empty() |
|
|
|
RingBuffer::empty() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return _tail == _head;
|
|
|
|
return _tail == _head; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
bool |
|
|
|
RingBuffer::full() |
|
|
|
RingBuffer::full() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return _next(_head) == _tail;
|
|
|
|
return _next(_head) == _tail; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned |
|
|
|
unsigned |
|
|
|
RingBuffer::size() |
|
|
|
RingBuffer::size() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return (_buf != nullptr) ? _num_items : 0;
|
|
|
|
return (_buf != nullptr) ? _num_items : 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
@ -86,7 +86,7 @@ RingBuffer::flush() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
bool |
|
|
|
RingBuffer::put(const void *val, size_t val_size)
|
|
|
|
RingBuffer::put(const void *val, size_t val_size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned next = _next(_head); |
|
|
|
unsigned next = _next(_head); |
|
|
|
if (next != _tail) { |
|
|
|
if (next != _tail) { |
|
|
@ -250,7 +250,7 @@ static inline bool my_sync_bool_compare_and_swap(volatile unsigned *a, unsigned |
|
|
|
#define __PX4_SBCAP __sync_bool_compare_and_swap |
|
|
|
#define __PX4_SBCAP __sync_bool_compare_and_swap |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
bool |
|
|
|
bool |
|
|
|
RingBuffer::get(void *val, size_t val_size)
|
|
|
|
RingBuffer::get(void *val, size_t val_size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_tail != _head) { |
|
|
|
if (_tail != _head) { |
|
|
|
unsigned candidate; |
|
|
|
unsigned candidate; |
|
|
@ -340,7 +340,7 @@ RingBuffer::get(double &val) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned |
|
|
|
unsigned |
|
|
|
RingBuffer::space(void)
|
|
|
|
RingBuffer::space(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned tail, head; |
|
|
|
unsigned tail, head; |
|
|
|
|
|
|
|
|
|
|
@ -361,7 +361,7 @@ RingBuffer::space(void) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned |
|
|
|
unsigned |
|
|
|
RingBuffer::count(void)
|
|
|
|
RingBuffer::count(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Note that due to the conservative nature of space(), this may |
|
|
|
* Note that due to the conservative nature of space(), this may |
|
|
@ -371,7 +371,7 @@ RingBuffer::count(void) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
bool |
|
|
|
RingBuffer::resize(unsigned new_size)
|
|
|
|
RingBuffer::resize(unsigned new_size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char *old_buffer; |
|
|
|
char *old_buffer; |
|
|
|
char *new_buffer = new char [(new_size+1) * _item_size]; |
|
|
|
char *new_buffer = new char [(new_size+1) * _item_size]; |
|
|
@ -388,13 +388,13 @@ RingBuffer::resize(unsigned new_size) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
RingBuffer::print_info(const char *name)
|
|
|
|
RingBuffer::print_info(const char *name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
printf("%s %u/%lu (%u/%u @ %p)\n", |
|
|
|
printf("%s %u/%lu (%u/%u @ %p)\n", |
|
|
|
name,
|
|
|
|
name, |
|
|
|
_num_items,
|
|
|
|
_num_items, |
|
|
|
(unsigned long)_num_items * _item_size,
|
|
|
|
(unsigned long)_num_items * _item_size, |
|
|
|
_head,
|
|
|
|
_head, |
|
|
|
_tail,
|
|
|
|
_tail, |
|
|
|
_buf); |
|
|
|
_buf); |
|
|
|
} |
|
|
|
} |
|
|
|