First fix for the ring buffer
This commit is contained in:
parent
8fc0d16e85
commit
08a73180d4
1 changed files with 2 additions and 1 deletions
|
@ -15,6 +15,7 @@ int ring_buffer_read(struct ring_buffer* rb, char* dest, int size) {
|
||||||
slice2 = used_space - slice1;
|
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, rb->buffer + rb->head, slice1);
|
||||||
memcpy(dest+slice1, rb->buffer, slice2);
|
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) {
|
int ring_buffer_free_space(struct ring_buffer* rb) {
|
||||||
if (rb->head > rb->tail) return rb->head - rb->tail;
|
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) {
|
int ring_buffer_used_space(struct ring_buffer* rb) {
|
||||||
|
|
Loading…
Reference in a new issue