diff --git a/include/EventManager/Manager.hpp b/include/EventManager/Manager.hpp index 7ba77b6..e186503 100644 --- a/include/EventManager/Manager.hpp +++ b/include/EventManager/Manager.hpp @@ -84,6 +84,12 @@ /// mutex to protect connectionQueue_ std::mutex mutexConnectionQueue_; + /// queue for disable scheduling request so the participants are not scheduled by the manager any longer + std::queue> disableScheduleQueue_; + + /// mutex to protect disableScheduleQueue_ + std::mutex mutexDisableScheduleQueue_; + /* * all private methods */ @@ -113,6 +119,14 @@ */ void processConnections_(); + /** + * @brief disables the scheduling of the requested participants + * + * Removes the participants from the schedulingParticipants_ list that + * should not be scheduled anymore. + */ + void processDisableScheduling_(); + /** * @brief start the main thread */ diff --git a/src/EventManager/Manager.cpp b/src/EventManager/Manager.cpp index 37bdb91..1499951 100644 --- a/src/EventManager/Manager.cpp +++ b/src/EventManager/Manager.cpp @@ -200,6 +200,7 @@ mutexSchedulingParticipants_.unlock(); processConnections_(); + processDisableScheduling_(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); } @@ -331,18 +332,14 @@ } } + void EventManager::Manager::unschedule(std::shared_ptr participant ) { - std::lock_guard guard(mutexSchedulingParticipants_); - - auto it = std::find(schedulingParticipants_.begin(), schedulingParticipants_.end(), participant); - - if (it != schedulingParticipants_.end()) - { - schedulingParticipants_.erase(it); - } + std::lock_guard guard( mutexDisableScheduleQueue_ ); + disableScheduleQueue_.push( participant ); } + void EventManager::Manager::processConnections_() { std::lock_guard guard(mutexParticipants_); @@ -354,11 +351,31 @@ connectionQueue_.pop(); participants_.push_back(participant); - participant->init(); } } + + void EventManager::Manager::processDisableScheduling_() + { + std::lock_guard guard( mutexDisableScheduleQueue_ ); + while( disableScheduleQueue_.empty() != true ) + { + std::shared_ptr participant = disableScheduleQueue_.front(); + disableScheduleQueue_.pop(); + + std::unique_lock lk(mutexSchedulingParticipants_); + auto it = std::find(schedulingParticipants_.begin(), schedulingParticipants_.end(), participant); + + if (it != schedulingParticipants_.end()) + { + schedulingParticipants_.erase(it); + } + lk.unlock(); + } + } + + void EventManager::Manager::connect(std::shared_ptr participant) { std::lock_guard guard(mutexParticipants_);