mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
Add support and test for concurrent TransitionTo
This commit is contained in:
committed by
Dennis Klein
parent
74d301a16f
commit
5256e7c580
@@ -106,6 +106,11 @@ FairMQDevice::FairMQDevice(ProgOptions* config, const tools::Version version)
|
||||
, fMaxRunRuntimeInS(DefaultMaxRunTime)
|
||||
, fInitializationTimeoutInS(DefaultInitTimeout)
|
||||
, fRawCmdLineArgs()
|
||||
, fStates()
|
||||
, fStatesMtx()
|
||||
, fStatesCV()
|
||||
, fTransitionMtx()
|
||||
, fTransitioning(false)
|
||||
{
|
||||
SubscribeToNewTransition("device", [&](Transition transition) {
|
||||
LOG(trace) << "device notified on new transition: " << transition;
|
||||
@@ -187,6 +192,15 @@ void FairMQDevice::WaitForState(fair::mq::State state)
|
||||
|
||||
void FairMQDevice::TransitionTo(const fair::mq::State s)
|
||||
{
|
||||
{
|
||||
lock_guard<mutex> lock(fTransitionMtx);
|
||||
if (fTransitioning) {
|
||||
LOG(debug) << "Attempting a transition with TransitionTo() while another one is already in progress";
|
||||
throw OngoingTransition("Attempting a transition with TransitionTo() while another one is already in progress");
|
||||
}
|
||||
fTransitioning = true;
|
||||
}
|
||||
|
||||
using fair::mq::State;
|
||||
State currentState = GetCurrentState();
|
||||
|
||||
@@ -225,6 +239,11 @@ void FairMQDevice::TransitionTo(const fair::mq::State s)
|
||||
|
||||
currentState = WaitForNextState();
|
||||
}
|
||||
|
||||
{
|
||||
lock_guard<mutex> lock(fTransitionMtx);
|
||||
fTransitioning = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQDevice::ChangeState(const int transition)
|
||||
|
@@ -44,6 +44,14 @@ using FairMQChannelMap = std::unordered_map<std::string, std::vector<FairMQChann
|
||||
using InputMsgCallback = std::function<bool(FairMQMessagePtr&, int)>;
|
||||
using InputMultipartCallback = std::function<bool(FairMQParts&, int)>;
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
struct OngoingTransition : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
}
|
||||
}
|
||||
|
||||
class FairMQDevice
|
||||
{
|
||||
friend class FairMQChannel;
|
||||
@@ -584,6 +592,9 @@ class FairMQDevice
|
||||
std::queue<fair::mq::State> fStates;
|
||||
std::mutex fStatesMtx;
|
||||
std::condition_variable fStatesCV;
|
||||
|
||||
std::mutex fTransitionMtx;
|
||||
bool fTransitioning;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQDEVICE_H_ */
|
||||
|
Reference in New Issue
Block a user