First fix for the ring buffer

This commit is contained in:
Quentin Dufour 2019-02-12 17:57:51 +01:00
parent 8fc0d16e85
commit 08a73180d4

View file

@ -15,6 +15,7 @@ int ring_buffer_read(struct ring_buffer* rb, char* dest, int size) {
slice2 = used_space - slice1;
}
printf("max_buffer=%d, head=%d, tail=%d, size=%d, slice1=%d, slice2=%d\n", RING_BUFFER_SIZE, rb->head, rb->tail, size, slice1, slice2);
memcpy(dest, rb->buffer + rb->head, slice1);
memcpy(dest+slice1, rb->buffer, slice2);
@ -53,7 +54,7 @@ int ring_buffer_write(struct ring_buffer* rb, char* source, int size) {
int ring_buffer_free_space(struct ring_buffer* rb) {
if (rb->head > rb->tail) return rb->head - rb->tail;
return RING_BUFFER_SIZE + (rb->tail - rb->head);
return RING_BUFFER_SIZE - (rb->tail - rb->head);
}
int ring_buffer_used_space(struct ring_buffer* rb) {