From ddb6d445dd3d61956203a4864797d0b4d17cd277 Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Wed, 11 Jul 2018 16:55:12 +0200 Subject: [PATCH] fixed blocking queue again --- FlippR-Driver/src/utilities/BlockingQueue.hpp | 57 ++----------------- .../tests/input/TestEventNotifier.cpp | 2 +- 2 files changed, 6 insertions(+), 53 deletions(-) diff --git a/FlippR-Driver/src/utilities/BlockingQueue.hpp b/FlippR-Driver/src/utilities/BlockingQueue.hpp index b6b6df3..049d7c6 100644 --- a/FlippR-Driver/src/utilities/BlockingQueue.hpp +++ b/FlippR-Driver/src/utilities/BlockingQueue.hpp @@ -10,7 +10,6 @@ #include #include -#include #include using namespace boost; @@ -19,74 +18,28 @@ template class BlockingQueue { private: -std::mutex mutex; -heap::priority_queue> p_queue; - -std::promise promise; -std::shared_future future_pop; + std::mutex d_mutex; + std::condition_variable d_condition; + heap::priority_queue> 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 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 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); - } }; diff --git a/FlippR-Driver/tests/input/TestEventNotifier.cpp b/FlippR-Driver/tests/input/TestEventNotifier.cpp index eb8f24d..c1397fb 100644 --- a/FlippR-Driver/tests/input/TestEventNotifier.cpp +++ b/FlippR-Driver/tests/input/TestEventNotifier.cpp @@ -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()); } }