The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
Diff: platform/CircularBuffer.h
- Revision:
- 171:3a7713b1edbc
- Parent:
- 170:e95d10626187
- Child:
- 172:65be27845400
--- a/platform/CircularBuffer.h Thu Sep 06 13:39:34 2018 +0100 +++ b/platform/CircularBuffer.h Thu Nov 08 11:45:42 2018 +0000 @@ -92,10 +92,14 @@ 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 @@ core_util_critical_section_enter(); if (!empty()) { data = _pool[_tail++]; - _tail %= BufferSize; + if (_tail == BufferSize) { + _tail = 0; + } _full = false; data_popped = true; } @@ -194,9 +200,9 @@ private: T _pool[BufferSize]; - volatile CounterType _head; - volatile CounterType _tail; - volatile bool _full; + CounterType _head; + CounterType _tail; + bool _full; }; /**@}*/