Exemplo n.º 1
0
unsigned Thread::Run()
{
    DebugLog << "Thread::Run" << std::endl;
    while (true)
    {
        if (mpThreadPool == NULL)
        {
            DebugLog << "mpThreadPool == NULL" << std::endl;
        }
        ITask* pTask = mpThreadPool->GetTask();
        if (pTask != NULL)
        {
            DebugLog << "Get a valid task" << std::endl;
            if (pTask->GetType() == TP_Exit)
            {
                pTask->OnComplete();
                mpThreadPool->FinishATask();
                break;
            }
            else if (pTask->GetType() == TP_Normal)
            {
                pTask->Run();
                pTask->OnComplete();
                mpThreadPool->FinishATask();
            }
        }
        else
        {
            DebugLog << "Get an invalid task" << std::endl;
        }
    }
    return 0;
}
Exemplo n.º 2
0
	void Worker::Run() {
		while (!_Shutdown) {
			ITask* currentJob = _Q->FetchTask();
			if (currentJob != NULL) {
				currentJob->Run();
				if (currentJob->ToBeDisposedByWorker()) {
					delete currentJob;
				}
			}
		}
	}
Exemplo n.º 3
0
 void QueueRunnable::run()
 {
     while (queue->IsStarted()) {
         queue->LockQueue();
         ITask* task = queue->NextTask();
         if (task == NULL) {
             queue->UnlockQueue();
             continue;
         }
         currentTask = task;
         queue->UnlockQueue();
         task->Run();
         queue->LockQueue();
         currentTask = NULL;
         queue->FinishTask(task);
         queue->NotifyQueue();
         queue->UnlockQueue();
     }
 }
    void ThreadPoolImpl::PopAndExecuteTask()
    {
        ITask* currentTask = nullptr;

        mutex_.Lock();

        if(!tasks_.empty())
        {
            currentTask = tasks_.front();
            tasks_.pop();

        }

        mutex_.UnLock();

        if (currentTask)
        {
            currentTask->Run();
            delete currentTask;
        }
    }
//---------------------------------------------------------------------------
void TTaskScheduler::Execute(wstring taskName){
    ITask *pITask = Activate(taskName);

    if(pITask == NULL){
        return;
    }



    ///////////////////////////////////////////////////////////////////
    // Call ITask::Run to start execution of "Test Task".
    ///////////////////////////////////////////////////////////////////

    HRESULT hr = pITask->Run();
    if (FAILED(hr)){
        sprintf(lastError, "Failed calling ITask::Run, error = 0x%x\n", hr);
        return;
    }


    pITask->Release();

}
    void NObjCommonBfTaskProfile::RunTask( DRI::IAsyncCmd *pAsyncCmd, ITask& task, const Domain::ObjectName& taskName, NObjBroadcastReceiver* postValidator)
    {        
        if (pAsyncCmd)
        {
            AsyncBegin(pAsyncCmd, boost::bind(&NObjCommonBfTaskProfile::AbortAsync, this));       
        }
        else
        {
            // это не первая задача
            ESS_ASSERT(AsyncActive());
        }

        m_postValidator = postValidator;       

        m_taskLog.reset(getDomain().LogCreator()->CreateSession(taskName.Name().toStdString(), m_traceClient));
        *m_taskLog << "RunTask" << iLogW::EndRecord;

        QString msg;
        msg += "Task ";
        msg += taskName.Name();
        msg += " started...";

        Log(msg);

        try
        {
            bool runAsLastTask;
            task.Run(runAsLastTask);
            if (!runAsLastTask) m_pNetTask = &task;
            else m_pNetTask = 0;
        }
        catch(const ESS::BaseException& e)
        {
            AsyncComplete(false, e.getTextMessage().c_str());
        }
    }