Merge pull request #7890 from deepikabhavnani/cb_issue_7701

Circular buffer should use conditional statement instead of modulo
pull/8274/head
Cruz Monrreal 2018-09-27 10:20:05 -05:00 committed by GitHub
commit 4403a561b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -92,10 +92,14 @@ public:
core_util_critical_section_enter();
if (full()) {
_tail++;
_tail %= BufferSize;
if (_tail == BufferSize) {
_tail = 0;
}
}
_pool[_head++] = data;
_head %= BufferSize;
if (_head == BufferSize) {
_head = 0;
}
if (_head == _tail) {
_full = true;
}
@ -113,7 +117,9 @@ public:
core_util_critical_section_enter();
if (!empty()) {
data = _pool[_tail++];
_tail %= BufferSize;
if (_tail == BufferSize) {
_tail = 0;
}
_full = false;
data_popped = true;
}