fixed blocking queue again
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <future>
|
||||
#include <boost/heap/priority_queue.hpp>
|
||||
|
||||
using namespace boost;
|
||||
@@ -19,74 +18,28 @@ template <typename T>
|
||||
class BlockingQueue
|
||||
{
|
||||
private:
|
||||
std::mutex mutex;
|
||||
heap::priority_queue<T, heap::stable<true>> p_queue;
|
||||
|
||||
std::promise<T> promise;
|
||||
std::shared_future<T> future_pop;
|
||||
std::mutex d_mutex;
|
||||
std::condition_variable d_condition;
|
||||
heap::priority_queue<T, heap::stable<true>> p_queue;
|
||||
|
||||
public:
|
||||
BlockingQueue()
|
||||
{
|
||||
this->future_pop = promise.get_future();
|
||||
}
|
||||
|
||||
void push(const T& value)
|
||||
{
|
||||
std::lock_guard lock(this->mutex);
|
||||
if(this->p_queue.empty())
|
||||
void push(T const& value)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
p_queue.push(value);
|
||||
}
|
||||
this->d_condition.notify_one();
|
||||
=======
|
||||
this->promise.set_value(value);
|
||||
return;
|
||||
>>>>>>> 3e086976076bbe7c104001de6366eff270d039fb
|
||||
}
|
||||
p_queue.push(value);
|
||||
}
|
||||
|
||||
T pop()
|
||||
{
|
||||
std::unique_lock lock(this->mutex);
|
||||
|
||||
auto status = future_pop.wait_for(std::chrono::seconds(0));
|
||||
if(status == std::future_status::ready)
|
||||
T pop()
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
// TODO die queue funzt net weil wir nich pushen koennen wenn wir im pop warten
|
||||
// TODO denk ma ueber future nach
|
||||
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;
|
||||
=======
|
||||
return future_pop.get();
|
||||
>>>>>>> 3e086976076bbe7c104001de6366eff270d039fb
|
||||
}
|
||||
|
||||
if (not this->p_queue.empty())
|
||||
{
|
||||
auto element = p_queue.top();
|
||||
p_queue.pop();
|
||||
return element;
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
|
||||
return future_pop.get();
|
||||
}
|
||||
|
||||
private:
|
||||
T get_first()
|
||||
{
|
||||
std::unique_lock lock(this->mutex);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ SCENARIO("An EventHandler gets [un]registered at the notifier", "[un-register no
|
||||
|
||||
THEN("The EventHandler gets saved")
|
||||
{
|
||||
REQUIRE(*(notifier.event_handler.find(&event_handler_mock.get())) == &event_handler_mock.get());
|
||||
REQUIRE(*notifier.event_handler.begin() == &event_handler_mock.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user