52 uint32_t size = elem_size * num_elem;
60 memset(ret, 0,
sizeof(*ret) + size);
91 if (rd_tail <= wr_head) {
106 *contig = rd_tail - wr_head - 1;
111 if (rd_tail <= wr_head) {
113 *avail = q->
num_elem - wr_head + rd_tail - 1;
116 *avail = rd_tail - wr_head - 1;
120 return contents + wr_head * q->
elem_size;
123 static inline uint16_t
advance_by_n(uint16_t num_pos, uint16_t current_pos,
124 uint16_t num_to_advance) {
128 uint32_t
pos = current_pos + num_to_advance;
130 if (pos >= num_pos) {
138 static inline uint16_t
next_pos(uint16_t num_pos, uint16_t current_pos) {
164 PIOS_Assert((new_write_head > orig_wr_head) || (new_write_head == 0));
215 if (wr_head >= read_tail) {
227 if (wr_head >= read_tail) {
233 *avail = q->
num_elem - read_tail + wr_head;
237 if (wr_head == read_tail) {
297 PIOS_Assert((read_tail > orig_read_tail) || (read_tail == 0));
303 uint16_t total_put = 0;
304 uint16_t put_this_time = 0;
306 const void *buf_pos = buf;
311 if (!put_this_time)
break;
313 if (put_this_time > (num - total_put)) {
314 put_this_time = num - total_put;
317 uint32_t sz = put_this_time * q->
elem_size;
319 memcpy(wr_pos, buf_pos, sz);
325 total_put += put_this_time;
326 }
while (total_put < num);
332 uint16_t total_read = 0;
333 uint16_t read_this_time = 0;
340 if (!read_this_time)
break;
342 if (read_this_time > (num - total_read)) {
343 read_this_time = num - total_read;
346 uint32_t sz = read_this_time * q->
elem_size;
348 memcpy(buf_pos, rd_pos, sz);
354 total_read += read_this_time;
355 }
while (total_read < num);
uint16_t circ_queue_read_data(circ_queue_t q, void *buf, uint16_t num)
volatile uint16_t write_head
uint16_t circ_queue_write_data(circ_queue_t q, const void *buf, uint16_t num)
void * PIOS_malloc(size_t size)
void circ_queue_read_completed_multi(circ_queue_t q, uint16_t num)
void * circ_queue_write_pos(circ_queue_t q, uint16_t *contig, uint16_t *avail)
static uint16_t advance_by_n(uint16_t num_pos, uint16_t current_pos, uint16_t num_to_advance)
circ_queue_t circ_queue_new(uint16_t elem_size, uint16_t num_elem)
void circ_queue_read_completed(circ_queue_t q)
Public header for 1 reader, 1 writer circular queue.
int circ_queue_advance_write(circ_queue_t q)
int circ_queue_advance_write_multi(circ_queue_t q, uint16_t amt)
void circ_queue_clear(circ_queue_t q)
volatile uint16_t read_tail
#define PIOS_Assert(test)
void * circ_queue_read_pos(circ_queue_t q, uint16_t *contig, uint16_t *avail)
static uint16_t next_pos(uint16_t num_pos, uint16_t current_pos)