Skip to content

Commit 4403a56

Browse files
author
Cruz Monrreal
authored
Merge pull request #7890 from deepikabhavnani/cb_issue_7701
Circular buffer should use conditional statement instead of modulo
2 parents 45f59f8 + 4e263b1 commit 4403a56

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

platform/CircularBuffer.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,14 @@ class CircularBuffer {
9292
core_util_critical_section_enter();
9393
if (full()) {
9494
_tail++;
95-
_tail %= BufferSize;
95+
if (_tail == BufferSize) {
96+
_tail = 0;
97+
}
9698
}
9799
_pool[_head++] = data;
98-
_head %= BufferSize;
100+
if (_head == BufferSize) {
101+
_head = 0;
102+
}
99103
if (_head == _tail) {
100104
_full = true;
101105
}
@@ -113,7 +117,9 @@ class CircularBuffer {
113117
core_util_critical_section_enter();
114118
if (!empty()) {
115119
data = _pool[_tail++];
116-
_tail %= BufferSize;
120+
if (_tail == BufferSize) {
121+
_tail = 0;
122+
}
117123
_full = false;
118124
data_popped = true;
119125
}

0 commit comments

Comments
 (0)