mirror of https://github.com/ARMmbed/mbed-os.git
Peek API to view data of buffer without popping
parent
3d1174a215
commit
9fa660ebde
|
@ -89,7 +89,7 @@ public:
|
|||
|
||||
/** Pop the transaction from the buffer
|
||||
*
|
||||
* @param data Data to be pushed to the buffer
|
||||
* @param data Data to be popped from the buffer
|
||||
* @return True if the buffer is not empty and data contains a transaction, false otherwise
|
||||
*/
|
||||
bool pop(T& data) {
|
||||
|
@ -154,6 +154,22 @@ public:
|
|||
core_util_critical_section_exit();
|
||||
return elements;
|
||||
}
|
||||
|
||||
/** Peek into circular buffer without popping
|
||||
*
|
||||
* @param data Data to be peeked from the buffer
|
||||
* @return True if the buffer is not empty and data contains a transaction, false otherwise
|
||||
*/
|
||||
bool peek(T& data) const {
|
||||
bool data_updated = false;
|
||||
core_util_critical_section_enter();
|
||||
if (!empty()) {
|
||||
data = _pool[_tail];
|
||||
data_updated = true;
|
||||
}
|
||||
core_util_critical_section_exit();
|
||||
return data_updated;
|
||||
}
|
||||
|
||||
private:
|
||||
T _pool[BufferSize];
|
||||
|
|
Loading…
Reference in New Issue