Skip to content

Commit

Permalink
Fix case where buffer is filled to capacity and becoming empty. There…
Browse files Browse the repository at this point in the history
… always needs to be an extra entry as a separator between the write and the read.
  • Loading branch information
n-a-c-h committed Feb 22, 2017
1 parent 095b48a commit 931fda4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/common/ringbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ template <typename T> class RingBuffer

void reset(size_type size)
{
this->m_size = size+1;
this->m_size = size+1; //Add one to allow for a seperator between the write and read pointers, and avoid various issues
this->m_pos_read = this->m_pos_write = 0;
this->m_buffer.reset(size ? this->m_size : 0);
}
Expand All @@ -58,7 +58,7 @@ template <typename T> class RingBuffer

size_type avail() const
{
return(this->m_size - this->used());
return((this->m_size-1) - this->used()); //Lose one from the size to prevent writing an entry casuing write to equal read pointer and causing other checks to think the buffer is empty
}

size_type used() const
Expand Down

0 comments on commit 931fda4

Please sign in to comment.