/* * BlockingQueue.hpp * * Created on: May 17, 2018 * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht */ #ifndef SRC_UTILITIES_BLOCKINGQUEUE_HPP_ #define SRC_UTILITIES_BLOCKINGQUEUE_HPP_ #include #include #include #include "IBlockingQueue.h" using namespace boost; namespace flippR_driver { namespace utility { template class BlockingQueue : public IBlockingQueue { private: std::mutex d_mutex; std::condition_variable d_condition; heap::priority_queue> p_queue; public: void push(T const &value) { { std::unique_lock lock(this->d_mutex); p_queue.push(value); } this->d_condition.notify_one(); } T pop() { std::unique_lock lock(this->d_mutex); this->d_condition.wait(lock, [=] { return !this->p_queue.empty(); }); T rc = *this->p_queue.begin(); this->p_queue.pop(); return rc; } }; } } #endif