From 16c3d418eb48020fe92e405cfddaea486df1168f Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sun, 10 May 2020 00:03:32 +0200 Subject: [PATCH] Buffer no longer volatile, not needed --- RingBuffer.h | 10 ++++++---- RingBuffer.impl.h | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/RingBuffer.h b/RingBuffer.h index 7a066b9..d8de703 100644 --- a/RingBuffer.h +++ b/RingBuffer.h @@ -47,15 +47,17 @@ template class CRingBuffer { public: - CRingBuffer(uint16_t length); + CRingBuffer(uint16_t length = 370U); uint16_t getSpace() const; uint16_t getData() const; - bool put(const volatile TDATATYPE item) volatile; + bool put(TDATATYPE item) volatile; - bool get(volatile TDATATYPE& item) volatile; + bool get(TDATATYPE& item); + + TDATATYPE get(); TDATATYPE peek() const; @@ -65,7 +67,7 @@ public: private: uint16_t m_length; - volatile TDATATYPE* m_buffer; + TDATATYPE* m_buffer; volatile uint16_t m_head; volatile uint16_t m_tail; volatile bool m_full; diff --git a/RingBuffer.impl.h b/RingBuffer.impl.h index 13c52e6..27bb8f6 100644 --- a/RingBuffer.impl.h +++ b/RingBuffer.impl.h @@ -56,14 +56,14 @@ template uint16_t CRingBuffer::getData() const return m_length - m_tail + m_head; } -template bool CRingBuffer::put(const TDATATYPE sample) volatile +template bool CRingBuffer::put(TDATATYPE item) volatile { if (m_full) { m_overflow = true; return false; } - m_buffer[m_head] = sample; + m_buffer[m_head] = item; m_head++; if (m_head >= m_length) @@ -80,7 +80,7 @@ template TDATATYPE CRingBuffer::peek() const return m_buffer[m_tail]; } -template bool CRingBuffer::get(volatile TDATATYPE& item) volatile +template bool CRingBuffer::get(TDATATYPE& item) { if (m_head == m_tail && !m_full) return false; @@ -111,4 +111,13 @@ template void CRingBuffer::reset() m_tail = 0U; m_full = false; m_overflow = false; -} \ No newline at end of file +} + +template TDATATYPE CRingBuffer::get() +{ + TDATATYPE value; + if(get(value)) + return value; + + //return 0U; +}