Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment from #629 in ring_buffer.c. #716

Merged
merged 1 commit into from
Jan 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions toxav/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ bool rb_full(const RingBuffer *b)
{
return (b->end + 1) % b->size == b->start;
}

bool rb_empty(const RingBuffer *b)
{
return b->end == b->start;
}

/*
* returns: NULL on success
* input value "p" on FAILURE -> caller can free on failed rb_write
*/
void *rb_write(RingBuffer *b, void *p)
{
void *rc = NULL;
Expand All @@ -55,6 +61,7 @@ void *rb_write(RingBuffer *b, void *p)

return rc;
}

bool rb_read(RingBuffer *b, void **p)
{
if (b->end == b->start) { /* Empty */
Expand All @@ -66,6 +73,7 @@ bool rb_read(RingBuffer *b, void **p)
b->start = (b->start + 1) % b->size;
return true;
}

RingBuffer *rb_new(int size)
{
RingBuffer *buf = (RingBuffer *)calloc(sizeof(RingBuffer), 1);
Expand All @@ -83,13 +91,15 @@ RingBuffer *rb_new(int size)

return buf;
}

void rb_kill(RingBuffer *b)
{
if (b) {
free(b->data);
free(b);
}
}

uint16_t rb_size(const RingBuffer *b)
{
if (rb_empty(b)) {
Expand All @@ -101,6 +111,7 @@ uint16_t rb_size(const RingBuffer *b)
b->end - b->start :
(b->size - b->start) + b->end;
}

uint16_t rb_data(const RingBuffer *b, void **dest)
{
uint16_t i = 0;
Expand Down