diff --git a/FlippR-Driver/src/utilities/BlockingQueue.hpp b/FlippR-Driver/src/utilities/BlockingQueue.hpp index 98a2a1e..b6b6df3 100644 --- a/FlippR-Driver/src/utilities/BlockingQueue.hpp +++ b/FlippR-Driver/src/utilities/BlockingQueue.hpp @@ -10,6 +10,7 @@ #include #include +#include #include using namespace boost; @@ -18,22 +19,45 @@ template class BlockingQueue { private: - std::mutex d_mutex; - std::condition_variable d_condition; - heap::priority_queue> p_queue; +std::mutex mutex; +heap::priority_queue> p_queue; + +std::promise promise; +std::shared_future future_pop; public: - void push(T const& value) +BlockingQueue() +{ + this->future_pop = promise.get_future(); +} + +void push(const T& value) +{ + std::lock_guard lock(this->mutex); + if(this->p_queue.empty()) { +<<<<<<< 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() +T pop() +{ + std::unique_lock lock(this->mutex); + + auto status = future_pop.wait_for(std::chrono::seconds(0)); + if(status == std::future_status::ready) { +<<<<<<< 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); @@ -41,12 +65,28 @@ public: T rc = *this->p_queue.begin(); this->p_queue.pop(); return rc; +======= + return future_pop.get(); +>>>>>>> 3e086976076bbe7c104001de6366eff270d039fb } - void release() + if (not this->p_queue.empty()) { - this->d_condition.notify_one(); + 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/TestDetector.cpp b/FlippR-Driver/tests/input/TestDetector.cpp index f681f7b..998bd10 100644 --- a/FlippR-Driver/tests/input/TestDetector.cpp +++ b/FlippR-Driver/tests/input/TestDetector.cpp @@ -6,8 +6,8 @@ */ -#include "../catch.hpp" -#include "../fakeit.hpp" +#include "catch.hpp" +#include "fakeit.hpp" #include #include @@ -60,11 +60,11 @@ SCENARIO("Creating a Detector object", "") AND_WHEN("an event can be found at gpio interface") { - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - THEN("only the fitting event should be distributed by event notifier") - { - REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2))); - } + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + THEN("after some time the only the fitting event should be distributed by event notifier") + { + REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2))); + } } } }