A template for ring buffer implementation
Dependents: AwsomeStation LoRaBaseStation LoRaTerminal
Revision 7:3e06927ef5ec, committed 2021-09-02
- Comitter:
- rba90
- Date:
- Thu Sep 02 00:16:51 2021 +0000
- Parent:
- 6:790344151d69
- Commit message:
- Rename CircularBuffer to RingBuffer
Changed in this revision
RingBuffer.cpp | Show annotated file Show diff for this revision Revisions of this file |
RingBuffer.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 790344151d69 -r 3e06927ef5ec RingBuffer.cpp --- a/RingBuffer.cpp Sat Sep 03 05:41:23 2016 +0000 +++ b/RingBuffer.cpp Thu Sep 02 00:16:51 2021 +0000 @@ -3,7 +3,7 @@ #include <stdlib.h> template <typename T> -CircularBuffer<T>::CircularBuffer(const size_t size) +RingBuffer<T>::RingBuffer(const size_t size) :buffer_size(size) { read_ptr = 0; @@ -24,32 +24,32 @@ } template <typename T> -CircularBuffer<T>::~CircularBuffer() +RingBuffer<T>::~RingBuffer() { // delete[] data; free(data); } template <typename T> -bool CircularBuffer<T>::isLocked() +bool RingBuffer<T>::isLocked() { return mux; } template <typename T> -void CircularBuffer<T>::lock() +void RingBuffer<T>::lock() { mux = true; } template <typename T> -void CircularBuffer<T>::unlock() +void RingBuffer<T>::unlock() { mux = false; } template <typename T> -void CircularBuffer<T>::enqueue(T in) +void RingBuffer<T>::enqueue(T in) { data[write_ptr++] = in; write_ptr %= buffer_size; @@ -58,7 +58,7 @@ } template <typename T> -T CircularBuffer<T>::dequeue() +T RingBuffer<T>::dequeue() { T temp = data[read_ptr++]; read_ptr %= buffer_size; @@ -68,56 +68,56 @@ } template <typename T> -size_t CircularBuffer<T>::getReadPtr() +size_t RingBuffer<T>::getReadPtr() { return read_ptr; } template <typename T> -size_t CircularBuffer<T>::getWritePtr() +size_t RingBuffer<T>::getWritePtr() { return write_ptr; } template <typename T> -size_t CircularBuffer<T>::getCounter() +size_t RingBuffer<T>::getCounter() { return count; } template <typename T> -bool CircularBuffer<T>::getOverFlow() +bool RingBuffer<T>::getOverFlow() { return is_over_flow; } template <typename T> -void CircularBuffer<T>::clearOverFlow() +void RingBuffer<T>::clearOverFlow() { is_over_flow = false; } template <typename T> -T CircularBuffer<T>::first() +T RingBuffer<T>::first() { return data[read_ptr]; } template <typename T> -T CircularBuffer<T>::last() +T RingBuffer<T>::last() { return data[write_ptr]; } template <typename T> -T CircularBuffer<T>::operator[](size_t idx) +T RingBuffer<T>::operator[](size_t idx) { return data[idx]; } // force compiler to create code for template -template class CircularBuffer<uint8_t>; +template class RingBuffer<uint8_t>; // forward declearation for AlohaFrame queue class AlohaFrame; -template class CircularBuffer<AlohaFrame *>; \ No newline at end of file +template class RingBuffer<AlohaFrame *>; \ No newline at end of file
diff -r 790344151d69 -r 3e06927ef5ec RingBuffer.h --- a/RingBuffer.h Sat Sep 03 05:41:23 2016 +0000 +++ b/RingBuffer.h Thu Sep 02 00:16:51 2021 +0000 @@ -7,7 +7,7 @@ #include <stdlib.h> template <typename T> -class CircularBuffer +class RingBuffer { private: const size_t buffer_size; @@ -26,8 +26,8 @@ public: - CircularBuffer(const size_t size=DEFAULT_MAX_BUFFER_SZ); - ~CircularBuffer(); + RingBuffer(const size_t size=DEFAULT_MAX_BUFFER_SZ); + ~RingBuffer(); // psudo mutex bool isLocked();