Index: src/libchcore/TBufferList.h =================================================================== diff -u -N -rc719644bb4360fcf7ccf6f1139bcae852bd6effd -rd99302fce795dbb5139659016a5da7948f141fb4 --- src/libchcore/TBufferList.h (.../TBufferList.h) (revision c719644bb4360fcf7ccf6f1139bcae852bd6effd) +++ src/libchcore/TBufferList.h (.../TBufferList.h) (revision d99302fce795dbb5139659016a5da7948f141fb4) @@ -23,6 +23,7 @@ #include #include "TCoreException.h" #include +#include "TSharedCountMT.h" namespace chcore { @@ -31,7 +32,8 @@ class TBufferList { public: - TBufferList() + TBufferList() : + m_spCount(std::make_shared>()) { } @@ -44,9 +46,8 @@ boost::unique_lock lock(m_mutex); m_queueBuffers.push_front(pBuffer); + m_spCount->Increase(); } - - m_notifier(); } TOverlappedDataBuffer* Pop() @@ -61,10 +62,9 @@ pBuffer = m_queueBuffers.front(); m_queueBuffers.pop_front(); + m_spCount->Decrease(); } - m_notifier(); - return pBuffer; } @@ -76,22 +76,18 @@ bRemoved = !m_queueBuffers.empty(); m_queueBuffers.clear(); + m_spCount->SetValue(0); } - - if(bRemoved) - m_notifier(); } size_t GetCount() const { - boost::shared_lock lock(m_mutex); - return m_queueBuffers.size(); + return m_spCount->GetValue(); } bool IsEmpty() const { - boost::shared_lock lock(m_mutex); - return m_queueBuffers.empty(); + return m_spCount->GetValue() == 0; } void SetExpectedBuffersCount(size_t stExpectedBuffers) // thread-unsafe by design @@ -103,21 +99,20 @@ bool AreAllBuffersAccountedFor() const { boost::shared_lock lock(m_mutex); - return m_stExpectedBuffers == m_queueBuffers.size(); + return m_stExpectedBuffers == m_spCount->GetValue(); } - boost::signals2::signal& GetNotifier() + TSharedCountMTPtr GetSharedCount() { - return m_notifier; + return m_spCount; } private: mutable boost::shared_mutex m_mutex; + TSharedCountMTPtr m_spCount; size_t m_stExpectedBuffers = 0; // count of buffers there should be in m_queueBuffers when no buffer is in use std::deque m_queueBuffers; - - boost::signals2::signal m_notifier; }; using TBufferListPtr = std::shared_ptr;