From 37b8f97d60191f521b16fe8114e6ccce7ccb39f2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 May 2014 15:47:48 +0200 Subject: [PATCH] C++11 migration: - use lambda functions instead of binding member functions - replace boost::mutex by STLs - reformat according to new guidelines --- DataStructures/ConcurrentQueue.h | 40 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/DataStructures/ConcurrentQueue.h b/DataStructures/ConcurrentQueue.h index 571d38b87..839b4363e 100644 --- a/DataStructures/ConcurrentQueue.h +++ b/DataStructures/ConcurrentQueue.h @@ -30,11 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../typedefs.h" -#include #include -#include -#include -#include +#include +#include +#include template class ConcurrentQueue { @@ -44,10 +43,12 @@ template class ConcurrentQueue inline void push(const Data &data) { - boost::mutex::scoped_lock lock(m_mutex); - m_not_full.wait(lock, boost::bind(&ConcurrentQueue::is_not_full, this)); + std::unique_lock lock(m_mutex); + m_not_full.wait(lock, + [this] + { return m_internal_queue.size() < m_internal_queue.capacity(); }); m_internal_queue.push_back(data); - lock.unlock(); + m_mutex.unlock(); m_not_empty.notify_one(); } @@ -55,40 +56,35 @@ template class ConcurrentQueue inline void wait_and_pop(Data &popped_value) { - boost::mutex::scoped_lock lock(m_mutex); - m_not_empty.wait(lock, boost::bind(&ConcurrentQueue::is_not_empty, this)); + std::unique_lock lock(m_mutex); + m_not_empty.wait(lock, + [this] + { return !m_internal_queue.empty(); }); popped_value = m_internal_queue.front(); m_internal_queue.pop_front(); - lock.unlock(); + m_mutex.unlock(); m_not_full.notify_one(); } inline bool try_pop(Data &popped_value) { - boost::mutex::scoped_lock lock(m_mutex); + std::unique_lock lock(m_mutex); if (m_internal_queue.empty()) { return false; } popped_value = m_internal_queue.front(); m_internal_queue.pop_front(); - lock.unlock(); + m_mutex.unlock(); m_not_full.notify_one(); return true; } private: - inline bool is_not_empty() const { return !m_internal_queue.empty(); } - - inline bool is_not_full() const - { - return m_internal_queue.size() < m_internal_queue.capacity(); - } - boost::circular_buffer m_internal_queue; - boost::mutex m_mutex; - boost::condition m_not_empty; - boost::condition m_not_full; + std::mutex m_mutex; + std::condition_variable m_not_empty; + std::condition_variable m_not_full; }; #endif // CONCURRENT_QUEUE_H