diff --git a/include/DataBuffer.h b/include/DataBuffer.h index 715ebac..d1c072c 100644 --- a/include/DataBuffer.h +++ b/include/DataBuffer.h @@ -34,7 +34,7 @@ template class DataBuffer { void push(std::vector &&samples) { if (!samples.empty()) { { - std::lock_guard lock(m_mutex); + std::scoped_lock lock{m_mutex}; m_qlen += samples.size(); m_queue.push(std::move(samples)); // unlock m_mutex here by getting out of scope @@ -46,7 +46,7 @@ template class DataBuffer { /** Mark the end of the data stream. */ void push_end() { { - std::lock_guard lock(m_mutex); + std::scoped_lock lock{m_mutex}; m_end_marked = true; // unlock m_mutex here by getting out of scope } @@ -56,7 +56,7 @@ template class DataBuffer { /** Return number of samples in queue. */ std::size_t queued_samples() { { - std::lock_guard lock(m_mutex); + std::scoped_lock lock{m_mutex}; return (m_qlen); // unlock m_mutex here by getting out of scope } @@ -86,7 +86,7 @@ template class DataBuffer { /** Return true if the end has been reached at the Pull side. */ bool pull_end_reached() { { - std::lock_guard lock(m_mutex); + std::scoped_lock lock{m_mutex}; return ((m_qlen == 0) && (m_end_marked)); // unlock m_mutex here by getting out of scope } @@ -94,8 +94,12 @@ template class DataBuffer { /** Wait until the buffer contains minfill samples or an end marker. */ void wait_buffer_fill(std::size_t minfill) { - std::unique_lock lock(m_mutex); - m_cond.wait(lock, [&] { return !((m_qlen < minfill) && (!m_end_marked)); }); + { + std::unique_lock lock(m_mutex); + m_cond.wait(lock, + [&] { return !((m_qlen < minfill) && (!m_end_marked)); }); + // unlock m_mutex here by getting out of scope + } } private: