예제 #1
0
void TaskExecutor::run()
{
  while (mActive) {
    TaskUnit* taskUnit = mTaskQueue.fetchNextTask();
    //If the queue returns a null pointer, it means that the queue is being shut down, and this executor is expected to exit its main processing loop.
    if (taskUnit) {
      try {
        TaskExecutionContext context(*this, *taskUnit);
        taskUnit->executeInBackgroundThread(context);
        mTaskQueue.addProcessedTask(taskUnit);
      } catch (const std::exception& ex) {
        S_LOG_CRITICAL("Error when executing task in background." << ex);
        delete taskUnit;
      } catch (...) {
        S_LOG_CRITICAL("Unknown error when executing task in background.");
        delete taskUnit;
      }
    } else {
      break;
    }
  }
}
예제 #2
0
void TaskExecutionContext::executeTask(ITask* task, ITaskExecutionListener* listener)
{
	TaskUnit* taskUnit = mTaskUnit.addSubtask(task, listener);
	TaskExecutionContext subtaskContext(mExecutor, *taskUnit);
	taskUnit->executeInBackgroundThread(subtaskContext);
}