diff --git a/fairmq/FairMQConfigurable.cxx b/fairmq/FairMQConfigurable.cxx index 49b0730b..9178142e 100644 --- a/fairmq/FairMQConfigurable.cxx +++ b/fairmq/FairMQConfigurable.cxx @@ -12,8 +12,6 @@ * @author D. Klein, A. Rybalchenko */ -#include // quick_exit() - #include "FairMQLogger.h" #include "FairMQConfigurable.h" @@ -26,7 +24,7 @@ FairMQConfigurable::FairMQConfigurable() void FairMQConfigurable::SetProperty(const int key, const string& value) { LOG(ERROR) << "Reached end of the property list. SetProperty(" << key << ", " << value << ") has no effect."; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } string FairMQConfigurable::GetProperty(const int key, const string& default_ /*= ""*/) @@ -38,7 +36,7 @@ string FairMQConfigurable::GetProperty(const int key, const string& default_ /*= void FairMQConfigurable::SetProperty(const int key, const int value) { LOG(ERROR) << "Reached end of the property list. SetProperty(" << key << ", " << value << ") has no effect."; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } int FairMQConfigurable::GetProperty(const int key, const int default_ /*= 0*/) diff --git a/fairmq/FairMQDevice.cxx b/fairmq/FairMQDevice.cxx index 058d02a6..81389404 100644 --- a/fairmq/FairMQDevice.cxx +++ b/fairmq/FairMQDevice.cxx @@ -15,7 +15,7 @@ #include #include // std::sort() #include // catching system signals -#include // quick_exit() +#include #include // for the InteractiveStateLoop @@ -57,15 +57,9 @@ void FairMQDevice::CatchSignals() { if (!fCatchingSignals) { - // setup signal catching sigHandler = bind1st(mem_fun(&FairMQDevice::SignalHandler), this); - struct sigaction action; - action.sa_handler = CallSignalHandler; - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - sigaction(SIGINT, &action, NULL); - sigaction(SIGTERM, &action, NULL); - + std::signal(SIGINT, CallSignalHandler); + std::signal(SIGTERM, CallSignalHandler); fCatchingSignals = true; } } @@ -74,17 +68,19 @@ void FairMQDevice::SignalHandler(int signal) { LOG(INFO) << "Caught signal " << signal; - // fState = EXITING; - // Unblock(); - // fStateThread.interrupt(); - // fStateThread.join(); + fState = EXITING; + Unblock(); + fStateThread.interrupt(); + fStateThread.join(); - // fTerminateStateThread = boost::thread(boost::bind(&FairMQDevice::Terminate, this)); - // Shutdown(); - // fTerminateStateThread.join(); + fTerminateStateThread = boost::thread(boost::bind(&FairMQDevice::Terminate, this)); + Shutdown(); + fTerminateStateThread.join(); MQLOG(INFO) << "Exiting."; - quick_exit(EXIT_FAILURE); + stop(); + std::abort(); + // exit(EXIT_FAILURE); } void FairMQDevice::InitWrapper() @@ -148,7 +144,7 @@ void FairMQDevice::InitWrapper() { LOG(ERROR) << "could not initialize all channels after " << maxAttempts << " attempts"; // TODO: goto ERROR state; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } if (numAttempts != 0) @@ -334,7 +330,7 @@ void FairMQDevice::Run() void FairMQDevice::Pause() { - while (CheckCurrentState(PAUSED)) + while (true) { try { @@ -481,7 +477,7 @@ void FairMQDevice::LogSocketRates() t0 = get_timestamp(); - while (CheckCurrentState(RUNNING)) + while (true) { try { diff --git a/fairmq/FairMQStateMachine.h b/fairmq/FairMQStateMachine.h index b6e1c69e..3d240aa0 100644 --- a/fairmq/FairMQStateMachine.h +++ b/fairmq/FairMQStateMachine.h @@ -62,12 +62,12 @@ struct FairMQFSM_ : public msm::front::state_machine_def { public: FairMQFSM_() - : fState() - , fStateThread() + : fStateThread() , fTerminateStateThread() , fStateFinished(false) , fStateCondition() , fStateMutex() + , fState() {} // Destructor @@ -87,7 +87,7 @@ struct FairMQFSM_ : public msm::front::state_machine_def } // The list of FSM states - struct NORMAL_FSM : public msm::front::state<> {}; + struct OK_FSM : public msm::front::state<> {}; struct ERROR_FSM : public msm::front::terminate_state<> {}; struct IDLE_FSM : public msm::front::state<> {}; @@ -102,7 +102,7 @@ struct FairMQFSM_ : public msm::front::state_machine_def struct EXITING_FSM : public msm::front::state<> {}; // Define initial states - typedef mpl::vector initial_state; + typedef mpl::vector initial_state; // Actions struct IdleFct @@ -314,7 +314,6 @@ struct FairMQFSM_ : public msm::front::state_machine_def LOG(STATE) << "ERROR!"; fsm.fState = ERROR; - // quick_exit(EXIT_FAILURE); } }; @@ -353,7 +352,7 @@ struct FairMQFSM_ : public msm::front::state_machine_def msmf::Row, msmf::Row, msmf::Row, - msmf::Row> + msmf::Row> {}; // Replaces the default no-transition response. @@ -366,7 +365,7 @@ struct FairMQFSM_ : public msm::front::state_machine_def // backward compatibility to FairMQStateMachine enum State { - NORMAL, + OK, ERROR, IDLE, INITIALIZING_DEVICE, @@ -384,8 +383,8 @@ struct FairMQFSM_ : public msm::front::state_machine_def { switch(state) { - case NORMAL: - return "NORMAL"; + case OK: + return "OK"; case ERROR: return "ERROR"; case IDLE: diff --git a/fairmq/devices/GenericSampler.tpl b/fairmq/devices/GenericSampler.tpl index dbc8ccda..4ebfbbee 100644 --- a/fairmq/devices/GenericSampler.tpl +++ b/fairmq/devices/GenericSampler.tpl @@ -83,6 +83,11 @@ void base_GenericSampler::Run() { fCurrentIdx--; } + + if (!CheckCurrentState(RUNNING)) + { + break; + } } } while (CheckCurrentState(RUNNING) && fContinuous); @@ -128,7 +133,7 @@ void base_GenericSampler::SetContinuous(bool flag) template void base_GenericSampler::ResetEventCounter() { - while (CheckCurrentState(RUNNING)) + while (true) { try { diff --git a/fairmq/examples/4-copypush/FairMQExample4Sampler.h b/fairmq/examples/4-copypush/FairMQExample4Sampler.h index af354c9e..2f7ff53e 100644 --- a/fairmq/examples/4-copypush/FairMQExample4Sampler.h +++ b/fairmq/examples/4-copypush/FairMQExample4Sampler.h @@ -12,8 +12,8 @@ * @author A. Rybalchenko */ -#ifndef FAIRMQEXAMPLESAMPLER_H_ -#define FAIRMQEXAMPLESAMPLER_H_ +#ifndef FAIRMQEXAMPLE4SAMPLER_H_ +#define FAIRMQEXAMPLE4SAMPLER_H_ #include diff --git a/fairmq/examples/4-copypush/FairMQExample4Sink.h b/fairmq/examples/4-copypush/FairMQExample4Sink.h index 58509a73..799ca84f 100644 --- a/fairmq/examples/4-copypush/FairMQExample4Sink.h +++ b/fairmq/examples/4-copypush/FairMQExample4Sink.h @@ -13,7 +13,7 @@ */ #ifndef FAIRMQEXAMPLE4SINK_H_ -#define FAIRMQEXAMPLE1SINK_H_ +#define FAIRMQEXAMPLE4SINK_H_ #include "FairMQDevice.h" diff --git a/fairmq/nanomsg/FairMQPollerNN.cxx b/fairmq/nanomsg/FairMQPollerNN.cxx index 8bfe65eb..45918ccd 100644 --- a/fairmq/nanomsg/FairMQPollerNN.cxx +++ b/fairmq/nanomsg/FairMQPollerNN.cxx @@ -12,8 +12,6 @@ * @author A. Rybalchenko */ -#include // quick_exit() - #include #include #include @@ -74,7 +72,7 @@ FairMQPollerNN::FairMQPollerNN(map>& channelsMap, { LOG(ERROR) << "At least one of the provided channel keys for poller initialization is invalid"; LOG(ERROR) << "Out of Range error: " << oor.what() << '\n'; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } } @@ -109,7 +107,7 @@ FairMQPollerNN::FairMQPollerNN(FairMQSocket& cmdSocket, FairMQSocket& dataSocket else { LOG(ERROR) << "invalid poller configuration, exiting."; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } } @@ -163,7 +161,7 @@ bool FairMQPollerNN::CheckInput(const string channelKey, const int index) { LOG(ERROR) << "Invalid channel key: \"" << channelKey << "\""; LOG(ERROR) << "Out of Range error: " << oor.what() << '\n'; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } } @@ -182,7 +180,7 @@ bool FairMQPollerNN::CheckOutput(const string channelKey, const int index) { LOG(ERROR) << "Invalid channel key: \"" << channelKey << "\""; LOG(ERROR) << "Out of Range error: " << oor.what() << '\n'; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } } diff --git a/fairmq/nanomsg/FairMQSocketNN.cxx b/fairmq/nanomsg/FairMQSocketNN.cxx index 74539aab..635bb3e5 100644 --- a/fairmq/nanomsg/FairMQSocketNN.cxx +++ b/fairmq/nanomsg/FairMQSocketNN.cxx @@ -12,7 +12,6 @@ * @author A. Rybalchenko */ -#include // quick_exit() #include #include "FairMQSocketNN.h" @@ -46,7 +45,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, const std::string& name, int if (fSocket == -1) { LOG(ERROR) << "failed creating socket " << fId << ", reason: " << nn_strerror(errno); - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } } else @@ -55,7 +54,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, const std::string& name, int if (fSocket == -1) { LOG(ERROR) << "failed creating socket " << fId << ", reason: " << nn_strerror(errno); - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } if (type == "sub") { diff --git a/fairmq/zeromq/FairMQContextZMQ.cxx b/fairmq/zeromq/FairMQContextZMQ.cxx index dcb95abd..ed8fe795 100644 --- a/fairmq/zeromq/FairMQContextZMQ.cxx +++ b/fairmq/zeromq/FairMQContextZMQ.cxx @@ -12,7 +12,6 @@ * @author D. Klein, A. Rybalchenko */ -#include // quick_exit() #include #include "FairMQLogger.h" @@ -25,7 +24,7 @@ FairMQContextZMQ::FairMQContextZMQ(int numIoThreads) if (fContext == NULL) { LOG(ERROR) << "failed creating context, reason: " << zmq_strerror(errno); - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } if (zmq_ctx_set(fContext, ZMQ_IO_THREADS, numIoThreads) != 0) diff --git a/fairmq/zeromq/FairMQPollerZMQ.cxx b/fairmq/zeromq/FairMQPollerZMQ.cxx index b8404187..c6859da3 100644 --- a/fairmq/zeromq/FairMQPollerZMQ.cxx +++ b/fairmq/zeromq/FairMQPollerZMQ.cxx @@ -12,8 +12,6 @@ * @author A. Rybalchenko */ -#include // quick_exit() - #include #include "FairMQPollerZMQ.h" @@ -74,7 +72,7 @@ FairMQPollerZMQ::FairMQPollerZMQ(map>& channelsMap { LOG(ERROR) << "At least one of the provided channel keys for poller initialization is invalid"; LOG(ERROR) << "Out of Range error: " << oor.what() << '\n'; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } } @@ -113,7 +111,7 @@ FairMQPollerZMQ::FairMQPollerZMQ(FairMQSocket& cmdSocket, FairMQSocket& dataSock else { LOG(ERROR) << "invalid poller configuration, exiting."; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } } @@ -167,7 +165,7 @@ bool FairMQPollerZMQ::CheckInput(const string channelKey, const int index) { LOG(ERROR) << "Invalid channel key: \"" << channelKey << "\""; LOG(ERROR) << "Out of Range error: " << oor.what() << '\n'; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } } @@ -186,7 +184,7 @@ bool FairMQPollerZMQ::CheckOutput(const string channelKey, const int index) { LOG(ERROR) << "Invalid channel key: \"" << channelKey << "\""; LOG(ERROR) << "Out of Range error: " << oor.what() << '\n'; - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } } diff --git a/fairmq/zeromq/FairMQSocketZMQ.cxx b/fairmq/zeromq/FairMQSocketZMQ.cxx index e3566843..1ca8c4aa 100644 --- a/fairmq/zeromq/FairMQSocketZMQ.cxx +++ b/fairmq/zeromq/FairMQSocketZMQ.cxx @@ -12,7 +12,6 @@ * @author D. Klein, A. Rybalchenko */ -#include // quick_exit() #include #include "FairMQSocketZMQ.h" @@ -44,7 +43,7 @@ FairMQSocketZMQ::FairMQSocketZMQ(const string& type, const string& name, int num if (fSocket == NULL) { LOG(ERROR) << "failed creating socket " << fId << ", reason: " << zmq_strerror(errno); - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } if (zmq_setsockopt(fSocket, ZMQ_IDENTITY, &fId, fId.length()) != 0) @@ -100,7 +99,7 @@ void FairMQSocketZMQ::Connect(const string& address) { LOG(ERROR) << "failed connecting socket " << fId << ", reason: " << zmq_strerror(errno); // error here means incorrect configuration. exit if it happens. - quick_exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } }