From e7b1eeeaa1bded531beda8cf2b29c80a5221d5cd Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Mon, 16 Aug 2021 20:12:05 +0200 Subject: [PATCH] ADD: check for timeout when waiting for event --- include/EventManager/Participant.hpp | 5 ++++- src/EventManager/Participant.cpp | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/EventManager/Participant.hpp b/include/EventManager/Participant.hpp index 8a3c76f..5846ca7 100644 --- a/include/EventManager/Participant.hpp +++ b/include/EventManager/Participant.hpp @@ -102,8 +102,11 @@ /** * @brief wait for a new event with timeout + * + * @return true - new event available and queue locked + * @return false - no new event, queue not locked, timeout reached */ - void _waitForEvent(std::uint32_t timeoutMS); + bool _waitForEvent(std::uint32_t timeoutMS); /** * @brief This method subscribes the participant to an event type diff --git a/src/EventManager/Participant.cpp b/src/EventManager/Participant.cpp index 35c2357..5d9f95f 100644 --- a/src/EventManager/Participant.cpp +++ b/src/EventManager/Participant.cpp @@ -94,11 +94,17 @@ void EventManager::Participant::_waitForEvent() isQueueLocked_=true; } -void EventManager::Participant::_waitForEvent(std::uint32_t timeoutMS) +bool EventManager::Participant::_waitForEvent(std::uint32_t timeoutMS) { std::unique_lock lock(mutexEventQueue_); - newEventInQueue_.wait_for(lock,timeoutMS*1ms); - isQueueLocked_=true; + if (newEventInQueue_.wait_for(lock,timeoutMS*1ms)==std::cv_status::no_timeout) + { + isQueueLocked_=true; + return true; + } + + return false; + }