Run InitTask in the worker thread (same as all other state handlers).

This commit is contained in:
Alexey Rybalchenko 2017-09-06 12:54:00 +02:00 committed by Mohammad Al-Turany
parent bfb9feab03
commit 6349438829
3 changed files with 12 additions and 9 deletions

View File

@ -482,8 +482,7 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
virtual void Init();
/// Task initialization (can be overloaded in child classes)
/// Executed in a worker thread (currently runs in main thread as workaround for multithread-aware FairRunAna/Sim implementation)
// TODO: fix this to also run in worker thread, or change all callbacks to be run in the main thread?
/// Executed in a worker thread
virtual void InitTask();
/// Runs the device (to be overloaded in child classes)

View File

@ -74,7 +74,7 @@ bool FairMQStateMachine::ChangeState(int event)
}
case internal_READY:
{
// std::lock_guard<std::mutex> lock(fChangeStateMutex); // InitTask is synchronous, until ROOT workaround is no longer needed.
std::lock_guard<std::mutex> lock(fChangeStateMutex);
process_event(FairMQFSM::internal_READY());
return true;
}
@ -154,6 +154,7 @@ void FairMQStateMachine::WaitForEndOfState(int event)
switch (event)
{
case INIT_DEVICE:
case INIT_TASK:
case RUN:
case RESET_TASK:
case RESET_DEVICE:
@ -166,8 +167,6 @@ void FairMQStateMachine::WaitForEndOfState(int event)
break;
}
case INIT_TASK:
break; // InitTask is synchronous, until ROOT workaround is no longer needed.
default:
LOG(ERROR) << "Requested state is either synchronous or does not exist.";
break;
@ -191,6 +190,7 @@ bool FairMQStateMachine::WaitForEndOfStateForMs(int event, int durationInMs)
switch (event)
{
case INIT_DEVICE:
case INIT_TASK:
case RUN:
case RESET_TASK:
case RESET_DEVICE:
@ -207,8 +207,6 @@ bool FairMQStateMachine::WaitForEndOfStateForMs(int event, int durationInMs)
return true;
break;
}
case INIT_TASK:
break; // InitTask is synchronous, until ROOT workaround is no longer needed.
default:
LOG(ERROR) << "Requested state is either synchronous or does not exist.";
return false;

View File

@ -176,8 +176,14 @@ struct FairMQFSM_ : public msmf::state_machine_def<FairMQFSM_>
LOG(STATE) << "Entering INITIALIZING TASK state";
fsm.fState = INITIALIZING_TASK;
fsm.InitTaskWrapper();
// fsm.fInitializingTaskThread = std::thread(&FairMQFSM_::InitTaskWrapper, &fsm);
std::unique_lock<std::mutex> lock(fsm.fWorkMutex);
while (fsm.fWorkActive)
{
fsm.fWorkDoneCondition.wait(lock);
}
fsm.fWorkAvailable = true;
fsm.fWork = std::bind(&FairMQFSM_::InitTaskWrapper, &fsm);
fsm.fWorkAvailableCondition.notify_one();
}
};