From: Lars Op den Kamp Date: Sun, 26 Feb 2012 21:28:04 +0000 (+0100) Subject: cec: lock in SyncedBuffer X-Git-Tag: upstream/2.2.0~1^2~33^2~33 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=120d4ca86e6f7e187e2d4a97e8fe9b8e31c85c8c;p=deb_libcec.git cec: lock in SyncedBuffer --- diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index 80670e4..95c4694 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -320,7 +320,7 @@ bool CUSBCECAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeou if (iTimeout == 0 || !m_rcvCondition.Wait(m_mutex, m_bHasData, iTimeout)) return false; m_inBuffer.Pop(buf); - m_bHasData = m_inBuffer.Size() > 0; + m_bHasData = !m_inBuffer.IsEmpty(); } if (buf) diff --git a/src/lib/platform/util/buffer.h b/src/lib/platform/util/buffer.h index ce6029c..56ffd64 100644 --- a/src/lib/platform/util/buffer.h +++ b/src/lib/platform/util/buffer.h @@ -40,24 +40,32 @@ namespace PLATFORM struct SyncedBuffer { public: - SyncedBuffer(size_t iMaxSize = 100) - { - m_maxSize = iMaxSize; - } + SyncedBuffer(size_t iMaxSize = 100) : + m_maxSize(iMaxSize) {} virtual ~SyncedBuffer(void) { - CLockObject lock(m_mutex, true); Clear(); } void Clear(void) { + CLockObject lock(m_mutex); while (!m_buffer.empty()) m_buffer.pop(); } - size_t Size(void) const { return m_buffer.size(); } + size_t Size(void) + { + CLockObject lock(m_mutex); + return m_buffer.size(); + } + + bool IsEmpty(void) + { + CLockObject lock(m_mutex); + return m_buffer.empty(); + } bool Push(_BType entry) {