ADD: protect eventMap with mutex

This commit is contained in:
Dominik Meyer 2022-02-18 22:49:09 +01:00
parent e7d90d0c87
commit 89f13445ba
No known key found for this signature in database
GPG Key ID: B4C312B600606B64
2 changed files with 7 additions and 1 deletions

View File

@ -50,6 +50,9 @@
/// map holding all the event type and plugin combinations
std::map<std::uint32_t, std::list<std::shared_ptr<EventManager::Participant>>> eventMap_;
/// mutex to protect the eventMap
std::mutex mutexEventMap_;
/// queue for incomng events
std::queue<std::shared_ptr<EventManager::Event>> eventQueue_;

View File

@ -12,6 +12,7 @@
#include <EventManager/Participant.hpp>
#include <iostream>
#include <algorithm>
#include <mutex>
void EventManager::Manager::startMain_()
{
@ -207,6 +208,7 @@
void EventManager::Manager::subscribe(std::uint32_t type, std::shared_ptr<EventManager::Participant> participant)
{
std::lock_guard<std::mutex> lockGuard(mutexEventMap_);
// check if participant is already registered
auto it = eventMap_.find(type);
@ -231,7 +233,8 @@
void EventManager::Manager::unsubscribe(std::uint32_t type, std::shared_ptr<EventManager::Participant> participant)
{
std::lock_guard<std::mutex> lockGuard(mutexEventMap_);
auto it = eventMap_.find(type);
if (it == eventMap_.end())