ADD: protect eventMap with mutex
This commit is contained in:
parent
e7d90d0c87
commit
89f13445ba
@ -50,6 +50,9 @@
|
|||||||
|
|
||||||
/// map holding all the event type and plugin combinations
|
/// map holding all the event type and plugin combinations
|
||||||
std::map<std::uint32_t, std::list<std::shared_ptr<EventManager::Participant>>> eventMap_;
|
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
|
/// queue for incomng events
|
||||||
std::queue<std::shared_ptr<EventManager::Event>> eventQueue_;
|
std::queue<std::shared_ptr<EventManager::Event>> eventQueue_;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <EventManager/Participant.hpp>
|
#include <EventManager/Participant.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
void EventManager::Manager::startMain_()
|
void EventManager::Manager::startMain_()
|
||||||
{
|
{
|
||||||
@ -207,6 +208,7 @@
|
|||||||
|
|
||||||
void EventManager::Manager::subscribe(std::uint32_t type, std::shared_ptr<EventManager::Participant> participant)
|
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
|
// check if participant is already registered
|
||||||
auto it = eventMap_.find(type);
|
auto it = eventMap_.find(type);
|
||||||
@ -231,7 +233,8 @@
|
|||||||
|
|
||||||
void EventManager::Manager::unsubscribe(std::uint32_t type, std::shared_ptr<EventManager::Participant> participant)
|
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);
|
auto it = eventMap_.find(type);
|
||||||
|
|
||||||
if (it == eventMap_.end())
|
if (it == eventMap_.end())
|
||||||
|
Loading…
Reference in New Issue
Block a user