Gracefully end the device also in the termination case (instead of abort).

This commit is contained in:
Alexey Rybalchenko 2016-05-17 08:55:42 +02:00
parent ce42f36126
commit e9f09143b2
3 changed files with 40 additions and 37 deletions

View File

@ -80,29 +80,29 @@ void FairMQDevice::SignalHandler(int signal)
{ {
LOG(INFO) << "Caught signal " << signal; LOG(INFO) << "Caught signal " << signal;
fState = EXITING; if (!fTerminated)
Unblock(); {
fStateThread.interrupt(); ChangeState(STOP);
fStateThread.join();
fTerminateStateThread = boost::thread(boost::bind(&FairMQDevice::Terminate, this)); ChangeState(RESET_TASK);
Shutdown(); WaitForEndOfState(RESET_TASK);
fTerminateStateThread.join();
stop(); ChangeState(RESET_DEVICE);
exit(EXIT_FAILURE); WaitForEndOfState(RESET_DEVICE);
// fRunning = false;
// if (!fTerminated) ChangeState(END);
// {
// fTerminated = true; // exit(EXIT_FAILURE);
// LOG(INFO) << "Exiting."; fRunning = false;
// } fTerminated = true;
// else LOG(INFO) << "Exiting.";
// { }
// LOG(WARN) << "Repeated termination or bad initialization? Aborting."; else
// // std::abort(); {
// exit(EXIT_FAILURE); LOG(WARN) << "Repeated termination or bad initialization? Aborting.";
// } // std::abort();
exit(EXIT_FAILURE);
}
} }
void FairMQDevice::ConnectChannels(list<FairMQChannel*>& chans) void FairMQDevice::ConnectChannels(list<FairMQChannel*>& chans)
@ -769,31 +769,31 @@ void FairMQDevice::InteractiveStateLoop()
{ {
case 'i': case 'i':
LOG(INFO) << "[i] init device"; LOG(INFO) << "[i] init device";
ChangeState("INIT_DEVICE"); ChangeState(INIT_DEVICE);
break; break;
case 'j': case 'j':
LOG(INFO) << "[j] init task"; LOG(INFO) << "[j] init task";
ChangeState("INIT_TASK"); ChangeState(INIT_TASK);
break; break;
case 'p': case 'p':
LOG(INFO) << "[p] pause"; LOG(INFO) << "[p] pause";
ChangeState("PAUSE"); ChangeState(PAUSE);
break; break;
case 'r': case 'r':
LOG(INFO) << "[r] run"; LOG(INFO) << "[r] run";
ChangeState("RUN"); ChangeState(RUN);
break; break;
case 's': case 's':
LOG(INFO) << "[s] stop"; LOG(INFO) << "[s] stop";
ChangeState("STOP"); ChangeState(STOP);
break; break;
case 't': case 't':
LOG(INFO) << "[t] reset task"; LOG(INFO) << "[t] reset task";
ChangeState("RESET_TASK"); ChangeState(RESET_TASK);
break; break;
case 'd': case 'd':
LOG(INFO) << "[d] reset device"; LOG(INFO) << "[d] reset device";
ChangeState("RESET_DEVICE"); ChangeState(RESET_DEVICE);
break; break;
case 'h': case 'h':
LOG(INFO) << "[h] help"; LOG(INFO) << "[h] help";
@ -801,11 +801,11 @@ void FairMQDevice::InteractiveStateLoop()
break; break;
// case 'x': // case 'x':
// LOG(INFO) << "[x] ERROR"; // LOG(INFO) << "[x] ERROR";
// ChangeState("ERROR_FOUND"); // ChangeState(ERROR_FOUND);
// break; // break;
case 'q': case 'q':
LOG(INFO) << "[q] end"; LOG(INFO) << "[q] end";
ChangeState("END"); ChangeState(END);
if (CheckCurrentState("EXITING")) if (CheckCurrentState("EXITING"))
{ {
fRunning = false; fRunning = false;

View File

@ -343,7 +343,7 @@ struct FairMQFSM_ : public msm::front::state_machine_def<FairMQFSM_>
virtual void Terminate() {} // Termination method called during StopFct action. virtual void Terminate() {} // Termination method called during StopFct action.
virtual void Unblock() {} // Method to send commands. virtual void Unblock() {} // Method to send commands.
// Transition table for FairMQFMS // Transition table for FairMQFSM
struct transition_table : mpl::vector< struct transition_table : mpl::vector<
// Start Event Next Action Guard // Start Event Next Action Guard
// +------------------------+----------------------+------------------------+----------------+---------+ // +------------------------+----------------------+------------------------+----------------+---------+
@ -369,7 +369,7 @@ struct FairMQFSM_ : public msm::front::state_machine_def<FairMQFSM_>
template <class FSM, class Event> template <class FSM, class Event>
void no_transition(Event const& e, FSM&, int state) void no_transition(Event const& e, FSM&, int state)
{ {
LOG(STATE) << "no transition from state " << GetStateName(state) << " on event " << e.name(); LOG(STATE) << "no transition from state " << GetStateName(state) << " (" << state << ") on event " << e.name();
} }
// backward compatibility to FairMQStateMachine // backward compatibility to FairMQStateMachine

View File

@ -48,13 +48,16 @@ inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config)
{ {
device.WaitForEndOfState(TMQDevice::RUN); device.WaitForEndOfState(TMQDevice::RUN);
device.ChangeState(TMQDevice::RESET_TASK); if (!device.CheckCurrentState(TMQDevice::EXITING))
device.WaitForEndOfState(TMQDevice::RESET_TASK); {
device.ChangeState(TMQDevice::RESET_TASK);
device.WaitForEndOfState(TMQDevice::RESET_TASK);
device.ChangeState(TMQDevice::RESET_DEVICE); device.ChangeState(TMQDevice::RESET_DEVICE);
device.WaitForEndOfState(TMQDevice::RESET_DEVICE); device.WaitForEndOfState(TMQDevice::RESET_DEVICE);
device.ChangeState(TMQDevice::END); device.ChangeState(TMQDevice::END);
}
} }
else else
{ {