Skip to content

Commit

Permalink
Device: synchronize access to transports container
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx committed Feb 22, 2023
1 parent ae7bc6f commit 7bf1d36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions fairmq/Device.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ bool Device::HandleMultipartInput(const string& chName, const InputMultipartCall

shared_ptr<TransportFactory> Device::AddTransport(mq::Transport transport)
{
lock_guard<mutex> lock(fTransportMtx);

if (transport == mq::Transport::DEFAULT) {
transport = fDefaultTransportType;
}
Expand Down Expand Up @@ -769,13 +771,15 @@ void Device::LogSocketRates()

void Device::InterruptTransports()
{
lock_guard<mutex> lock(fTransportMtx);
for (auto& [transportType, transport] : fTransports) {
transport->Interrupt();
}
}

void Device::ResumeTransports()
{
lock_guard<mutex> lock(fTransportMtx);
for (auto& [transportType, transport] : fTransports) {
transport->Resume();
}
Expand All @@ -792,14 +796,17 @@ void Device::ResetTaskWrapper()

void Device::ResetWrapper()
{
for (auto& [transportType, transport] : fTransports) {
transport->Reset();
{
lock_guard<mutex> lock(fTransportMtx);
for (auto& [transportType, transport] : fTransports) {
transport->Reset();
}
fTransports.clear();
}

Reset();

fChannels.clear();
fTransports.clear();
fTransportFactory.reset();
if (!NewStatePending()) {
ChangeState(Transition::Auto);
Expand Down
1 change: 1 addition & 0 deletions fairmq/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ class Device

StateQueue fStateQueue;

std::mutex fTransportMtx; ///< guards access to transports container
std::mutex fTransitionMtx;
bool fTransitioning;
};
Expand Down

0 comments on commit 7bf1d36

Please sign in to comment.