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(); virtual void Init();
/// Task initialization (can be overloaded in child classes) /// 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) /// Executed in a worker thread
// TODO: fix this to also run in worker thread, or change all callbacks to be run in the main thread?
virtual void InitTask(); virtual void InitTask();
/// Runs the device (to be overloaded in child classes) /// Runs the device (to be overloaded in child classes)

View File

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

View File

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