ADD: check for timeout when waiting for event

This commit is contained in:
Dominik Meyer 2021-08-16 20:12:05 +02:00
parent 789ce929a4
commit e7b1eeeaa1
No known key found for this signature in database
GPG Key ID: B4C312B600606B64
2 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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<std::mutex> 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;
}