ADD: method to wait for new event with timeout

This commit is contained in:
Dominik Meyer 2021-08-16 20:07:07 +02:00
parent 8f78070770
commit 789ce929a4
No known key found for this signature in database
GPG Key ID: B4C312B600606B64
2 changed files with 15 additions and 0 deletions

View File

@ -100,6 +100,10 @@
*/
void _waitForEvent();
/**
* @brief wait for a new event with timeout
*/
void _waitForEvent(std::uint32_t timeoutMS);
/**
* @brief This method subscribes the participant to an event type

View File

@ -11,6 +11,9 @@
#include <EventManager/Participant.hpp>
#include <EventManager/Manager.hpp>
#include <iostream>
#include <chrono>
using namespace std::chrono_literals;
EventManager::Participant::Participant() : manager_(nullptr),
isScheduledByManager_(false), isQueueLocked_(false)
@ -91,6 +94,14 @@ void EventManager::Participant::_waitForEvent()
isQueueLocked_=true;
}
void EventManager::Participant::_waitForEvent(std::uint32_t timeoutMS)
{
std::unique_lock<std::mutex> lock(mutexEventQueue_);
newEventInQueue_.wait_for(lock,timeoutMS*1ms);
isQueueLocked_=true;
}
void EventManager::Participant::_enableScheduling()
{
if (manager_ == nullptr)