Skip to content

Commit 546743a

Browse files
author
Deepika
committed
Replace modulo op with compare/reset op
1 parent 7c22dca commit 546743a

File tree

1 file changed

+9
-3
lines changed

1 file 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)