Lines Matching refs:rb

46 void ringbuffer_free(ringbuffer_t* rb) {  in ringbuffer_free()  argument
47 if (rb != nullptr) free(rb->base); in ringbuffer_free()
48 free(rb); in ringbuffer_free()
51 size_t ringbuffer_available(const ringbuffer_t* rb) { in ringbuffer_available() argument
52 assert(rb); in ringbuffer_available()
53 return rb->available; in ringbuffer_available()
56 size_t ringbuffer_size(const ringbuffer_t* rb) { in ringbuffer_size() argument
57 assert(rb); in ringbuffer_size()
58 return rb->total - rb->available; in ringbuffer_size()
61 size_t ringbuffer_insert(ringbuffer_t* rb, const uint8_t* p, size_t length) { in ringbuffer_insert() argument
62 assert(rb); in ringbuffer_insert()
65 if (length > ringbuffer_available(rb)) length = ringbuffer_available(rb); in ringbuffer_insert()
68 *rb->tail++ = *p++; in ringbuffer_insert()
69 if (rb->tail >= (rb->base + rb->total)) rb->tail = rb->base; in ringbuffer_insert()
72 rb->available -= length; in ringbuffer_insert()
76 size_t ringbuffer_delete(ringbuffer_t* rb, size_t length) { in ringbuffer_delete() argument
77 assert(rb); in ringbuffer_delete()
79 if (length > ringbuffer_size(rb)) length = ringbuffer_size(rb); in ringbuffer_delete()
81 rb->head += length; in ringbuffer_delete()
82 if (rb->head >= (rb->base + rb->total)) rb->head -= rb->total; in ringbuffer_delete()
84 rb->available += length; in ringbuffer_delete()
88 size_t ringbuffer_peek(const ringbuffer_t* rb, off_t offset, uint8_t* p, in ringbuffer_peek() argument
90 assert(rb); in ringbuffer_peek()
93 assert((size_t)offset <= ringbuffer_size(rb)); in ringbuffer_peek()
95 uint8_t* b = ((rb->head - rb->base + offset) % rb->total) + rb->base; in ringbuffer_peek()
96 const size_t bytes_to_copy = (offset + length > ringbuffer_size(rb)) in ringbuffer_peek()
97 ? ringbuffer_size(rb) - offset in ringbuffer_peek()
102 if (b >= (rb->base + rb->total)) b = rb->base; in ringbuffer_peek()
108 size_t ringbuffer_pop(ringbuffer_t* rb, uint8_t* p, size_t length) { in ringbuffer_pop() argument
109 assert(rb); in ringbuffer_pop()
112 const size_t copied = ringbuffer_peek(rb, 0, p, length); in ringbuffer_pop()
113 rb->head += copied; in ringbuffer_pop()
114 if (rb->head >= (rb->base + rb->total)) rb->head -= rb->total; in ringbuffer_pop()
116 rb->available += copied; in ringbuffer_pop()