From 90cf0f6f58a7793a7e671142788b0fc938d382b8 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 27 Jan 2024 11:51:22 +0100 Subject: [PATCH] Added reset() method to RingBuffer class --- openrtx/include/core/ringbuf.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/openrtx/include/core/ringbuf.hpp b/openrtx/include/core/ringbuf.hpp index 2e652987..49e5afcb 100644 --- a/openrtx/include/core/ringbuf.hpp +++ b/openrtx/include/core/ringbuf.hpp @@ -175,6 +175,20 @@ public: pthread_mutex_unlock(&mutex); } + /** + * Reset the buffer to its empty state discarding all the elements stored. + * + * Note: reset is "lazy", as it just sets read pointer, write pointer and + * number of elements to zero. No actual erasure of the stored elements is + * done until they are effectively overwritten by new push()es. + */ + void reset() + { + readPos = 0; + writePos = 0; + numElements = 0; + } + private: size_t readPos; ///< Read pointer.