Skip to content

Commit 9fa660e

Browse files
author
Deepika
committed
Peek API to view data of buffer without popping
1 parent 3d1174a commit 9fa660e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

platform/CircularBuffer.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CircularBuffer {
8989

9090
/** Pop the transaction from the buffer
9191
*
92-
* @param data Data to be pushed to the buffer
92+
* @param data Data to be popped from the buffer
9393
* @return True if the buffer is not empty and data contains a transaction, false otherwise
9494
*/
9595
bool pop(T& data) {
@@ -154,6 +154,22 @@ class CircularBuffer {
154154
core_util_critical_section_exit();
155155
return elements;
156156
}
157+
158+
/** Peek into circular buffer without popping
159+
*
160+
* @param data Data to be peeked from the buffer
161+
* @return True if the buffer is not empty and data contains a transaction, false otherwise
162+
*/
163+
bool peek(T& data) const {
164+
bool data_updated = false;
165+
core_util_critical_section_enter();
166+
if (!empty()) {
167+
data = _pool[_tail];
168+
data_updated = true;
169+
}
170+
core_util_critical_section_exit();
171+
return data_updated;
172+
}
157173

158174
private:
159175
T _pool[BufferSize];

0 commit comments

Comments
 (0)