From 23f04f472f860253d09b9707fc5ff2bce7f546a1 Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Mon, 7 May 2018 11:39:48 +0200 Subject: [PATCH] fixing compile errors --- FlippR-Driver/src/input/Detector.cpp | 15 ++++++++------- FlippR-Driver/src/input/Detector.h | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/FlippR-Driver/src/input/Detector.cpp b/FlippR-Driver/src/input/Detector.cpp index 3271918..d6ffd2b 100644 --- a/FlippR-Driver/src/input/Detector.cpp +++ b/FlippR-Driver/src/input/Detector.cpp @@ -23,7 +23,6 @@ Detector::Detector(std::map input_config, std::map event_handler_guard(event_handler_mutex); + LOCK_EVENT_HANDLER(); event_handler.insert(handler); } void Detector::unregister_input_event_handler(InputEventHandler* handler) { - std::lock_guard event_handler_guard(event_handler_mutex); + LOCK_EVENT_HANDLER(); event_handler.erase(handler); } @@ -55,10 +54,11 @@ void Detector::notify_handlers() return; } - InputEvent& event = event_queue.pop(); - - std::lock_guard event_handler_guard(event_handler_mutex); + InputEvent event = event_queue.front(); + event_queue.pop(); + // getting a guard and calling all registered handlers + LOCK_EVENT_HANDLER(); for(auto* handler : event_handler) { handler->handle(event); @@ -66,6 +66,7 @@ void Detector::notify_handlers() } } + void Detector::detect() { while(is_running) @@ -74,7 +75,7 @@ void Detector::detect() if(check_inputs(address)) { InputEvent& event = input_events.at(address); - event_queue.queue(event); + event_queue.emplace(event); } } } diff --git a/FlippR-Driver/src/input/Detector.h b/FlippR-Driver/src/input/Detector.h index 5e7116a..7482641 100644 --- a/FlippR-Driver/src/input/Detector.h +++ b/FlippR-Driver/src/input/Detector.h @@ -16,8 +16,11 @@ #include "InputEvent.h" +#define LOCK_EVENT_HANDLER() std::lock_guard event_handler_guard(event_handler_mutex) + #define SLEEP_DURATION_NANO 900 + namespace Input {