Fix regression in the DDS plugin shutdown handling

This commit is contained in:
Alexey Rybalchenko 2019-11-20 13:50:32 +01:00 committed by Dennis Klein
parent f6e3183f45
commit 073f5e5c0e
2 changed files with 10 additions and 3 deletions

View File

@ -87,7 +87,6 @@ DDS::DDS(const string& name,
// subscribe to device state changes, pushing new state changes into the event queue // subscribe to device state changes, pushing new state changes into the event queue
SubscribeToDeviceStateChange([&](DeviceState newState) { SubscribeToDeviceStateChange([&](DeviceState newState) {
fStateQueue.Push(newState);
switch (newState) { switch (newState) {
case DeviceState::Bound: case DeviceState::Bound:
// Receive addresses of connecting channels from DDS // Receive addresses of connecting channels from DDS
@ -109,7 +108,11 @@ DDS::DDS(const string& name,
} }
case DeviceState::Exiting: case DeviceState::Exiting:
fWorkGuard.reset(); fWorkGuard.reset();
{
unique_lock<mutex> lock(fStopMutex);
fDeviceTerminationRequested = true; fDeviceTerminationRequested = true;
}
fStopCondition.notify_one();
UnsubscribeFromDeviceStateChange(); UnsubscribeFromDeviceStateChange();
ReleaseDeviceControl(); ReleaseDeviceControl();
break; break;
@ -373,6 +376,7 @@ auto DDS::SubscribeForCustomCommands() -> void
inCmds.Deserialize(cmdStr); inCmds.Deserialize(cmdStr);
for (const auto& cmd : inCmds) { for (const auto& cmd : inCmds) {
// LOG(info) << "Received command type: '" << cmd->GetType() << "' from " << senderId;
switch (cmd->GetType()) { switch (cmd->GetType()) {
case Type::check_state: { case Type::check_state: {
fDDS.Send(Cmds(make<CurrentState>(id, GetCurrentDeviceState())).Serialize(), to_string(senderId)); fDDS.Send(Cmds(make<CurrentState>(id, GetCurrentDeviceState())).Serialize(), to_string(senderId));
@ -387,6 +391,10 @@ auto DDS::SubscribeForCustomCommands() -> void
Cmds outCmds(make<TransitionStatus>(id, Result::Failure, transition)); Cmds outCmds(make<TransitionStatus>(id, Result::Failure, transition));
fDDS.Send(outCmds.Serialize(), to_string(senderId)); fDDS.Send(outCmds.Serialize(), to_string(senderId));
} }
{
lock_guard<mutex> lock{fStateChangeSubscriberMutex};
fLastExternalController = senderId;
}
} }
break; break;
case Type::dump_config: { case Type::dump_config: {

View File

@ -161,7 +161,6 @@ class DDS : public Plugin
std::thread fControllerThread; std::thread fControllerThread;
DeviceState fCurrentState, fLastState; DeviceState fCurrentState, fLastState;
fair::mq::StateQueue fStateQueue;
std::atomic<bool> fDeviceTerminationRequested; std::atomic<bool> fDeviceTerminationRequested;