From 12f04c72378fa26d12921db2cad49c793861d9eb Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Tue, 15 Nov 2016 13:08:38 +0100 Subject: [PATCH] Fix race condition in the state machine & channel. --- fairmq/FairMQChannel.cxx | 1 + fairmq/FairMQStateMachine.cxx | 1 + fairmq/FairMQStateMachine.h | 6 +++--- fairmq/plugins/control/FairMQDDSControlPlugin.cxx | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fairmq/FairMQChannel.cxx b/fairmq/FairMQChannel.cxx index 88280189..f46e779f 100644 --- a/fairmq/FairMQChannel.cxx +++ b/fairmq/FairMQChannel.cxx @@ -539,6 +539,7 @@ bool FairMQChannel::InitCommandInterface(FairMQTransportFactory* factory, int nu void FairMQChannel::ResetChannel() { + boost::unique_lock scoped_lock(fChannelMutex); fIsValid = false; // TODO: implement channel resetting } diff --git a/fairmq/FairMQStateMachine.cxx b/fairmq/FairMQStateMachine.cxx index c72cb838..4664b920 100644 --- a/fairmq/FairMQStateMachine.cxx +++ b/fairmq/FairMQStateMachine.cxx @@ -133,6 +133,7 @@ void FairMQStateMachine::WaitForEndOfState(int event) { fStateCondition.wait(lock); } + fStateThread.join(); } catch (boost::exception& e) { diff --git a/fairmq/FairMQStateMachine.h b/fairmq/FairMQStateMachine.h index c36235a3..2c640fd2 100644 --- a/fairmq/FairMQStateMachine.h +++ b/fairmq/FairMQStateMachine.h @@ -250,8 +250,8 @@ struct FairMQFSM_ : public msm::front::state_machine_def template void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&) { - LOG(STATE) << "RUNNING state finished without an external event, going to IDLE"; - + LOG(STATE) << "RUNNING state finished without an external event"; + LOG(STATE) << "Entering READY state"; fsm.fState = READY; } }; @@ -380,7 +380,7 @@ struct FairMQFSM_ : public msm::front::state_machine_def std::size_t pos = stateName.find("_FSME"); stateName.erase(pos); - if (stateName == "1RUNNING" || stateName == "6DEVICE_READY" || stateName == "0PAUSED") + if (stateName == "1RUNNING" || stateName == "6DEVICE_READY" || stateName == "0PAUSED" || stateName == "8RESETTING_TASK") { stateName = stateName.substr(1); } diff --git a/fairmq/plugins/control/FairMQDDSControlPlugin.cxx b/fairmq/plugins/control/FairMQDDSControlPlugin.cxx index e06f520e..9179eb50 100644 --- a/fairmq/plugins/control/FairMQDDSControlPlugin.cxx +++ b/fairmq/plugins/control/FairMQDDSControlPlugin.cxx @@ -18,6 +18,7 @@ #include #include #include +#include using namespace std; using namespace dds::intercom_api;