47 _num_items(num_items),
48 _item_size(item_size),
49 _buf(new char[(_num_items + 1) * item_size]),
62 return (0 == index) ?
_num_items : (index - 1);
97 if ((val_size == 0) || (val_size >
_item_size)) {
113 return put(&val,
sizeof(val));
119 return put(&val,
sizeof(val));
125 return put(&val,
sizeof(val));
131 return put(&val,
sizeof(val));
137 return put(&val,
sizeof(val));
143 return put(&val,
sizeof(val));
149 return put(&val,
sizeof(val));
155 return put(&val,
sizeof(val));
161 return put(&val,
sizeof(val));
167 return put(&val,
sizeof(val));
173 bool overwrote =
false;
176 if (
put(val, val_size)) {
190 return force(&val,
sizeof(val));
196 return force(&val,
sizeof(val));
202 return force(&val,
sizeof(val));
208 return force(&val,
sizeof(val));
214 return force(&val,
sizeof(val));
220 return force(&val,
sizeof(val));
226 return force(&val,
sizeof(val));
232 return force(&val,
sizeof(val));
238 return force(&val,
sizeof(val));
244 return force(&val,
sizeof(val));
249 #define __PX4_SBCAP my_sync_bool_compare_and_swap 250 static inline bool my_sync_bool_compare_and_swap(
volatile unsigned *a,
unsigned b,
unsigned c)
261 #define __PX4_SBCAP __sync_bool_compare_and_swap 270 if ((val_size == 0) || (val_size >
_item_size)) {
279 next =
_next(candidate);
282 if (val !=
nullptr) {
299 return get(&val,
sizeof(val));
305 return get(&val,
sizeof(val));
311 return get(&val,
sizeof(val));
317 return get(&val,
sizeof(val));
323 return get(&val,
sizeof(val));
329 return get(&val,
sizeof(val));
335 return get(&val,
sizeof(val));
341 return get(&val,
sizeof(val));
347 return get(&val,
sizeof(val));
353 return get(&val,
sizeof(val));
372 }
while (head !=
_head);
374 return (tail >= head) ? (
_num_items - (tail - head)) : (head - tail - 1);
391 char *new_buffer =
new char [(new_size + 1) *
_item_size];
393 if (new_buffer ==
nullptr) {
409 printf(
"%s %u/%lu (%u/%u @ %p)\n",
volatile unsigned _tail
removal point in _item_size units
void print_info(const char *name)
bool get(void *val, size_t val_size=0)
Get an item from the buffer.
bool put(const void *val, size_t val_size=0)
Put an item into the buffer.
bool resize(unsigned new_size)
volatile unsigned _head
insertion point in _item_size units
static unsigned char _buf[2048]
unsigned _next(unsigned index)
bool force(const void *val, size_t val_size=0)
Force an item into the buffer, discarding an older item if there is not space.