FIX: fixed deadlock when participant connects another one
This commit is contained in:
parent
c2a609c913
commit
92975e8349
@ -78,14 +78,20 @@
|
||||
/// the id for the next participant connecting
|
||||
std::uint32_t nextParticipantID_;
|
||||
|
||||
/*
|
||||
* all private methods
|
||||
*/
|
||||
/// queue for connection request so connecting is done in manager context
|
||||
std::queue<std::shared_ptr<EventManager::Participant>> connectionQueue_;
|
||||
|
||||
/**
|
||||
* @brief the method running in the main thread
|
||||
*/
|
||||
void mainProcess_();
|
||||
/// mutex to protect connectionQueue_
|
||||
std::mutex mutexConnectionQueue_;
|
||||
|
||||
/*
|
||||
* all private methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief the method running in the main thread
|
||||
*/
|
||||
void mainProcess_();
|
||||
|
||||
/**
|
||||
* @brief the method running in the scheduling thread
|
||||
@ -97,6 +103,9 @@
|
||||
*/
|
||||
void processEvent(const std::shared_ptr<EventManager::Event> event);
|
||||
|
||||
|
||||
void processConnections_();
|
||||
|
||||
/**
|
||||
* @brief start the main thread
|
||||
*/
|
||||
|
@ -198,6 +198,8 @@
|
||||
}
|
||||
}
|
||||
mutexSchedulingParticipants_.unlock();
|
||||
|
||||
processConnections_();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
@ -341,18 +343,34 @@
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::Manager::processConnections_()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mutexParticipants_);
|
||||
std::lock_guard<std::mutex> lockGuard(mutexConnectionQueue_);
|
||||
|
||||
while(!connectionQueue_.empty())
|
||||
{
|
||||
std::shared_ptr<EventManager::Participant> participant = connectionQueue_.front();
|
||||
connectionQueue_.pop();
|
||||
particpants_.push_back(participant);
|
||||
|
||||
|
||||
participant->init();
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::Manager::connect(std::shared_ptr<EventManager::Participant> participant)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mutexParticipants_);
|
||||
particpants_.push_back(participant);
|
||||
participant->setManager(shared_from_this());
|
||||
|
||||
// we can set and increment here because only one participant is in this critical
|
||||
// section in any moment
|
||||
// we can set and increment here because only one participant is in this
|
||||
// critical section in any moment
|
||||
participant->setID(nextParticipantID_);
|
||||
nextParticipantID_++;
|
||||
|
||||
participant->init();
|
||||
|
||||
connectionQueue_.push(participant);
|
||||
|
||||
}
|
||||
|
||||
void EventManager::Manager::disconnect(std::shared_ptr<EventManager::Participant> participant)
|
||||
|
Loading…
Reference in New Issue
Block a user