From 1ed68d302d6601c5efe0aeca79986d3f22884b2c Mon Sep 17 00:00:00 2001 From: Christina Sander Date: Tue, 30 Aug 2022 12:43:42 +0200 Subject: [PATCH 1/3] FIX: fixes spelling error in variablename participants_ (list of connected participants in the manager). --- include/EventManager/Manager.hpp | 2 +- src/EventManager/Manager.cpp | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/EventManager/Manager.hpp b/include/EventManager/Manager.hpp index e484dee..a1be6a3 100644 --- a/include/EventManager/Manager.hpp +++ b/include/EventManager/Manager.hpp @@ -70,7 +70,7 @@ std::mutex mutexSchedulingParticipants_; /// list of all participants connected - std::list> particpants_; + std::list> participants_; /// mutex to protect participants_ std::mutex mutexParticipants_; diff --git a/src/EventManager/Manager.cpp b/src/EventManager/Manager.cpp index 6eda276..37bdb91 100644 --- a/src/EventManager/Manager.cpp +++ b/src/EventManager/Manager.cpp @@ -352,7 +352,7 @@ { std::shared_ptr participant = connectionQueue_.front(); connectionQueue_.pop(); - particpants_.push_back(participant); + participants_.push_back(participant); participant->init(); @@ -375,20 +375,17 @@ void EventManager::Manager::disconnect(std::shared_ptr participant) { - disconnect(participant); std::lock_guard guard(mutexParticipants_); std::list>::iterator it; - it = std::find(particpants_.begin(), particpants_.end(),participant); + it = std::find(participants_.begin(), participants_.end(),participant); - if (it != particpants_.end()) + if (it != participants_.end()) { - particpants_.erase(it); + participants_.erase(it); } - - participant->setManager(nullptr); } -- 2.45.2 From 5c2fc37748191ee924dc15222cc241e4ef649fd1 Mon Sep 17 00:00:00 2001 From: Christina Sander Date: Tue, 30 Aug 2022 15:12:31 +0200 Subject: [PATCH 2/3] ADD: Adds comment to processConnections_ class function of the manager --- include/EventManager/Manager.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/EventManager/Manager.hpp b/include/EventManager/Manager.hpp index a1be6a3..7ba77b6 100644 --- a/include/EventManager/Manager.hpp +++ b/include/EventManager/Manager.hpp @@ -103,7 +103,14 @@ */ void processEvent(const std::shared_ptr event); - + /** + * @brief adds the queued participants to the list of connected participants + * + * The connectionQueue_ contains the participants that should be connected to + * the manager. All connected participants are stored in the list participants_. + * This class function adds the queued participants to the list participants_ + * and removes them from the queue. + */ void processConnections_(); /** -- 2.45.2 From d268273e3ca37c64b657a3ffd2190923b904b989 Mon Sep 17 00:00:00 2001 From: Christina Sander Date: Tue, 30 Aug 2022 15:12:51 +0200 Subject: [PATCH 3/3] FIX: fixes deadlock bug of class function to disable scheduling When calling _diableScheduling of the participant to enable the own participant for scheduling by the manager the process runned in a deadlock. Summary: 1. manager locks mutex mutexSchedulingParticipants_ 2. calls schedule class function of participants in the schedulingParticipants_ list 3. there the _disableScheduling function is called by the participant 4. which calls the unschedule function of the manager 5. manager tries to lock mutexSchedulingParticipants_ which is already locked Solution: - this commit adds the following elements to the Manager class: 1. disableScheduleQueue_ 2. mutexDisableScheduleQueue_ 3. processDisableScheduling_() ( like processConnections() ) - this commit changes the following functions of Manager class: 1. unschedule( ... ) -> now adds given participant to disableScheduleQueue 2. scheduleProcess_() -> now also calls the class function processDisableSchedulung_() after processConections_() --- include/EventManager/Manager.hpp | 14 +++++++++++++ src/EventManager/Manager.cpp | 35 ++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 9 deletions(-) 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_); -- 2.45.2