refactored utility namespace

This commit is contained in:
Jonas Zeunert
2018-10-17 22:00:56 +02:00
parent 8708663cd6
commit c5867acd52
15 changed files with 154 additions and 61 deletions

View File

@@ -0,0 +1,57 @@
/*
* 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 <mutex>
#include <condition_variable>
#include <boost/heap/priority_queue.hpp>
#include "IBlockingQueue.h"
using namespace boost;
namespace FlippR_Driver
{
namespace utility
{
template<typename T>
class BlockingQueue : public IBlockingQueue<T>
{
private:
std::mutex d_mutex;
std::condition_variable d_condition;
heap::priority_queue<T, heap::stable<true>> p_queue;
public:
void push(T const &value)
{
{
std::unique_lock<std::mutex> lock(this->d_mutex);
p_queue.push(value);
}
this->d_condition.notify_one();
}
T pop()
{
std::unique_lock<std::mutex> 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