int main(int argc, char* argv[]) { if (!RunTask(BINARY_DIR"/input.txt")) return 1; return 0; }
/* * ======== main ======== */ int main(int argc, char **argv) { INT nStrmMode = 0; FILE *inFile = NULL; /* Input file handle. */ FILE *outFile = NULL; /* Output file handle. */ struct STRMCOPY_TASK strmcopyTask; int status = 0; DspManager_Open(argc, NULL); /* Process command line arguments, open data files: */ status = ProcessArgs(argc, argv, &inFile, &outFile, &nStrmMode); strmcopyTask.hProcessor = NULL; strmcopyTask.hNode = NULL; strmcopyTask.hInStream = NULL; strmcopyTask.hOutStream = NULL; strmcopyTask.ppInBufs = NULL; strmcopyTask.ppOutBufs = NULL; strmcopyTask.nStrmMode = nStrmMode; if (DSP_SUCCEEDED(status)) { /* Perform processor level initialization. */ status = InitializeProcessor(&strmcopyTask); } if (DSP_SUCCEEDED(status)) { /* Perform node level initialization. */ status = InitializeNode(&strmcopyTask); if (DSP_SUCCEEDED(status)) { /* Perform stream level initialization. */ status = InitializeStreams(&strmcopyTask); if (DSP_SUCCEEDED(status)) { /* Run task. */ status = RunTask(&strmcopyTask, inFile, outFile); if (DSP_SUCCEEDED(status)) { fprintf(stdout, "RunTask succeeded.\n"); } else { fprintf(stdout, "RunTask failed.\n"); } } } } /* Close opened files. */ if (inFile) { fclose(inFile); } if (outFile) { fclose(outFile); } CleanupStreams(&strmcopyTask); CleanupNode(&strmcopyTask); CleanupProcessor(&strmcopyTask); DspManager_Close(0, NULL); /*printf("Hit enter to exit: "); (void)getchar(); */ return (DSP_SUCCEEDED(status) ? 0 : -1); }
/* * ======== main ======== */ int main(int argc, char **argv) { struct SCALE_TASK scaleTask; int status = 0; status = (DBAPI)DspManager_Open(0, NULL); if (DSP_FAILED(status)) { printf("\nFATAL ERROR: Bridge Initialisation FAILED\n"); return 0; } status = ProcessArgs(argc, argv, &scaleTask); /* initialize context object */ scaleTask.hProcessor = NULL; scaleTask.hNode = NULL; scaleTask.hInStream = NULL; scaleTask.hOutStream = NULL; scaleTask.pInBuf = NULL; scaleTask.pOutBuf = NULL; if (DSP_SUCCEEDED(status)) { /* do processor level initialization */ status = InitializeProcessor(&scaleTask); if (DSP_SUCCEEDED(status)) { /* do node level initialization */ status = InitializeNode(&scaleTask); if (DSP_SUCCEEDED(status)) { /* do stream level initialization */ status = InitializeStreams(&scaleTask); if (DSP_SUCCEEDED(status)) { /* do processing */ status = RunTask(&scaleTask); if (DSP_SUCCEEDED(status)) { fprintf(stdout, "\nRunTask succeeded.\n"); } else { fprintf(stdout, "\nRunTask failed.\n"); } } } } } CleanupStreams(&scaleTask); CleanupNode(&scaleTask); CleanupProcessor(&scaleTask); status = DspManager_Close(0, NULL); if (DSP_FAILED(status)) { printf("\nERROR: Bridge Close FAILED\n"); } return (DSP_SUCCEEDED(status) ? 0 : -1); }
QStringList Pipeline::RunTaskList(const QList<Task*>& taskList) { errors.clear(); emit progressUpdated(0); for(Task* task : taskList) { QString error = CheckTask(task); if(error.isNull()) RunTask(task); else errors.push_back(ERROR_MASK.arg(task->name).arg(error)); } curStages = 0; return errors; }
bool Worker::getTasks() { vector<string> children; int code = zk->getChildren(m_assign_dir, true, &children); //LOG_INFO("got children:%d task num:%d", children.size(), m_tasks.size()); if (code != ZOK) return false; //find deleted task set<string> tasks(children.begin(), children.end()); for (map<string, Task*>::iterator it = m_tasks.begin(); it != m_tasks.end(); ) { if (tasks.find(it->first) == tasks.end()) { //deleted task delete it->second; LOG_INFO("delete task:%s", it->first.c_str()); m_tasks.erase(it++); } else { ++it; } } //find added task for (int i = 0; i < children.size(); ++i) { if (m_tasks.find(children[i]) == m_tasks.end()) { Task *info = getTaskInfo(children[i]); if (info != NULL) { //new task LOG_INFO("add task:%s", children[i].c_str()); m_tasks[children[i]] = info; RunTask(children[i]); } } } return true; }
static NTSTATUS ProcessRunnable( PEPOLL_THREAD pThread, PRING pRunnable, PRING pTimed, PRING pWaiting, LONG64 llNow ) { NTSTATUS status = STATUS_SUCCESS; ULONG ulTicks = MAX_TICKS; PLW_TASK pTask = NULL; PLW_TASK_GROUP pGroup = NULL; PRING pRing = NULL; PRING pNext = NULL; /* We are guaranteed to run each task at least once. If tasks remain on the runnable list by yielding, we will continue to run them all in a round robin until our ticks are depleted. */ while (ulTicks && !RingIsEmpty(pRunnable)) { for (pRing = pRunnable->pNext; pRing != pRunnable; pRing = pNext) { pNext = pRing->pNext; pTask = LW_STRUCT_FROM_FIELD(pRing, EPOLL_TASK, QueueRing); RunTask(pTask, llNow); if (ulTicks) { ulTicks--; } if (pTask->EventWait != LW_TASK_EVENT_COMPLETE) { /* Task is still waiting to be runnable, update events in epoll set */ status = UpdateEventWait( pTask, pThread->EpollFd ); GOTO_ERROR_ON_STATUS(status); if (pTask->EventWait & LW_TASK_EVENT_YIELD) { /* Task is yielding. Set YIELD in its trigger arguments and and leave it on the runnable list for the next iteration */ pTask->EventArgs |= LW_TASK_EVENT_YIELD; } else if (pTask->EventWait & LW_TASK_EVENT_TIME) { /* If the task is waiting for a timeout, insert it into the timed queue */ RingRemove(&pTask->QueueRing); InsertTimedQueue(pTimed, pTask); } else { /* Otherwise, put it in the generic waiting queue */ RingRemove(&pTask->QueueRing); RingEnqueue(pWaiting, &pTask->QueueRing); } } else { /* Task is complete */ RingRemove(&pTask->QueueRing); /* Turn off any fd in the epoll set */ if (pTask->Fd >= 0) { status = LwRtlSetTaskFd(pTask, pTask->Fd, 0); GOTO_ERROR_ON_STATUS(status); } /* Unsubscribe task from any UNIX signals */ if (pTask->pUnixSignal) { RegisterTaskUnixSignal(pTask, 0, FALSE); } LOCK_POOL(pThread->pPool); pThread->ulLoad--; UNLOCK_POOL(pThread->pPool); pGroup = pTask->pGroup; /* If task was in a task group, remove it and notify anyone waiting on the group */ if (pGroup) { LOCK_GROUP(pGroup); pTask->pGroup = NULL; RingRemove(&pTask->GroupRing); pthread_cond_broadcast(&pGroup->Event); UNLOCK_GROUP(pGroup); } LOCK_THREAD(pThread); if (--pTask->ulRefCount) { /* The task still has a reference, so mark it as completed and notify anyone waiting on it */ pTask->EventSignal = TASK_COMPLETE_MASK; pthread_cond_broadcast(&pThread->Event); UNLOCK_THREAD(pThread); } else { /* We held the last reference to the task, so delete it */ RingRemove(&pTask->SignalRing); UNLOCK_THREAD(pThread); TaskDelete(pTask); } } } } error: return status; }
//========================================================= // MaintainSchedule - does all the per-think schedule maintenance. // ensures that the monster leaves this function with a valid // schedule! //========================================================= void CBaseMonster :: MaintainSchedule ( void ) { Schedule_t *pNewSchedule; int i; // UNDONE: Tune/fix this 10... This is just here so infinite loops are impossible for ( i = 0; i < 10; i++ ) { if ( m_pSchedule != NULL && TaskIsComplete() ) { NextScheduledTask(); } // validate existing schedule if ( !FScheduleValid() || m_MonsterState != m_IdealMonsterState ) { // if we come into this block of code, the schedule is going to have to be changed. // if the previous schedule was interrupted by a condition, GetIdealState will be // called. Else, a schedule finished normally. // Notify the monster that his schedule is changing ScheduleChange(); // Call GetIdealState if we're not dead and one or more of the following... // - in COMBAT state with no enemy (it died?) // - conditions bits (excluding SCHEDULE_DONE) indicate interruption, // - schedule is done but schedule indicates it wants GetIdealState called // after successful completion (by setting bits_COND_SCHEDULE_DONE in iInterruptMask) // DEAD & SCRIPT are not suggestions, they are commands! if ( m_IdealMonsterState != MONSTERSTATE_DEAD && (m_IdealMonsterState != MONSTERSTATE_SCRIPT || m_IdealMonsterState == m_MonsterState) ) { // if we're here, then either we're being told to do something (besides dying or playing a script) // or our current schedule (besides dying) is invalid. -- LRC if ( (m_afConditions && !HasConditions(bits_COND_SCHEDULE_DONE)) || (m_pSchedule && (m_pSchedule->iInterruptMask & bits_COND_SCHEDULE_DONE)) || ((m_MonsterState == MONSTERSTATE_COMBAT) && (m_hEnemy == NULL)) ) { GetIdealState(); } } if ( HasConditions( bits_COND_TASK_FAILED ) && m_MonsterState == m_IdealMonsterState ) { if ( m_failSchedule != SCHED_NONE ) pNewSchedule = GetScheduleOfType( m_failSchedule ); else pNewSchedule = GetScheduleOfType( SCHED_FAIL ); // schedule was invalid because the current task failed to start or complete ALERT ( at_aiconsole, "Schedule Failed at %d!\n", m_iScheduleIndex ); ChangeSchedule( pNewSchedule ); } else { SetState( m_IdealMonsterState ); if ( m_MonsterState == MONSTERSTATE_SCRIPT || m_MonsterState == MONSTERSTATE_DEAD ) { pNewSchedule = CBaseMonster::GetSchedule(); } else pNewSchedule = GetSchedule(); ChangeSchedule( pNewSchedule ); } } if ( m_iTaskStatus == TASKSTATUS_NEW ) { Task_t *pTask = GetTask(); ASSERT( pTask != NULL ); TaskBegin(); StartTask( pTask ); } // UNDONE: Twice?!!! if ( m_Activity != m_IdealActivity ) { SetActivity ( m_IdealActivity ); } if ( !TaskIsComplete() && m_iTaskStatus != TASKSTATUS_NEW ) break; } if ( TaskIsRunning() ) { Task_t *pTask = GetTask(); ASSERT( pTask != NULL ); RunTask( pTask ); } // UNDONE: We have to do this so that we have an animation set to blend to if RunTask changes the animation // RunTask() will always change animations at the end of a script! // Don't do this twice if ( m_Activity != m_IdealActivity ) { SetActivity ( m_IdealActivity ); } }
static VOID ProcessRunnable( PKQUEUE_THREAD pThread, PKQUEUE_COMMANDS pCommands, PRING pRunnable, PRING pTimed, PRING pWaiting, LONG64 llNow ) { ULONG ulTicks = MAX_TICKS; PLW_TASK pTask = NULL; PLW_TASK_GROUP pGroup = NULL; PRING pRing = NULL; PRING pNext = NULL; /* We are guaranteed to run each task at least once. If tasks remain on the runnable list by yielding, we will continue to run them all in a round robin until our ticks are depleted. */ while (ulTicks && !RingIsEmpty(pRunnable)) { for (pRing = pRunnable->pNext; pRing != pRunnable; pRing = pNext) { pNext = pRing->pNext; pTask = LW_STRUCT_FROM_FIELD(pRing, KQUEUE_TASK, QueueRing); RunTask(pTask, llNow); if (ulTicks) { ulTicks--; } if (pTask->EventWait != LW_TASK_EVENT_COMPLETE) { if (pTask->EventWait & LW_TASK_EVENT_YIELD) { /* Task is yielding. Set the YIELD flag and leave it on the runnable list for the next iteration. */ pTask->EventArgs |= LW_TASK_EVENT_YIELD; } else { /* Task is still waiting on events, update kqueue */ UpdateEventWait(pCommands, pTask); if (pTask->EventWait & LW_TASK_EVENT_TIME) { /* If the task is waiting for a timeout, insert it into the timed queue */ RingRemove(&pTask->QueueRing); InsertTimedQueue(pTimed, pTask); } else { /* Otherwise, put it in the generic waiting queue */ RingRemove(&pTask->QueueRing); RingEnqueue(pWaiting, &pTask->QueueRing); } } } else { /* Task is complete */ RingRemove(&pTask->QueueRing); /* Remove any associated events from the kqueue */ if (pTask->Fd >= 0) { (void) LwRtlSetTaskFd(pTask, pTask->Fd, 0); } /* Unsubscribe task from any UNIX signals */ if (pTask->pUnixSignal) { RegisterTaskUnixSignal(pTask, 0, FALSE); } LOCK_POOL(pThread->pPool); pThread->ulLoad--; UNLOCK_POOL(pThread->pPool); pGroup = pTask->pGroup; /* If task was in a task group, remove it and notify anyone waiting on the group */ if (pGroup) { LOCK_GROUP(pGroup); pTask->pGroup = NULL; RingRemove(&pTask->GroupRing); pthread_cond_broadcast(&pGroup->Event); UNLOCK_GROUP(pGroup); } LOCK_THREAD(pThread); if (--pTask->ulRefCount) { /* The task still has a reference, so mark it as completed and notify anyone waiting on it */ pTask->EventSignal = TASK_COMPLETE_MASK; pthread_cond_broadcast(&pThread->Event); UNLOCK_THREAD(pThread); } else { /* We held the last reference to the task, so delete it */ RingRemove(&pTask->SignalRing); UNLOCK_THREAD(pThread); TaskDelete(pTask); } } } } /* Update kevent commands for yielding tasks */ for (pRing = pRunnable->pNext; pRing != pRunnable; pRing = pRing->pNext) { pTask = LW_STRUCT_FROM_FIELD(pRing, KQUEUE_TASK, QueueRing); if (pTask->EventArgs & LW_TASK_EVENT_YIELD) { UpdateEventWait(pCommands, pTask); } } }
long DoCommand( HWND hWindow, UINT idCmd, HWND hControl, UINT codeNotify ) /***********************************************************************/ { FNAME szFileName; BOOL bPrint; LPTSTR lpszCmdLine; LPIMAGE lpImage; lpImage = GetActiveImage(); //if ( lpImage && idCmd >= PS_FIRST_PLUGIN && idCmd <= PS_LAST_PLUGIN ) if( idCmd >= PS_FIRST_PLUGIN && idCmd <= PS_LAST_PLUGIN ) { DeactivateTool(); return( HandlePluginCommand( lpImage, MDIFrame_wParam, MDIFrame_lParam )); } //if ( lpImage && idCmd >= PS_FIRST_ADOBEPLUGIN && idCmd <= PS_LAST_ADOBEPLUGIN ) if( idCmd >= PS_FIRST_ADOBEPLUGIN && idCmd <= PS_LAST_ADOBEPLUGIN ) { DeactivateTool(); return( HandleAdobePluginCommand( lpImage, idCmd )); } // handle messages which should be passed to the ribbons if (WITHIN(idCmd, IDM_FIRST_RIBBONMENU, IDM_LAST_RIBBONMENU)) { if(Tool.hRibbon) SEND_WM_COMMAND(Tool.hRibbon, idCmd, hControl, codeNotify); } switch (idCmd) { case IDM_RECALLIMAGE0: case IDM_RECALLIMAGE1: case IDM_RECALLIMAGE2: case IDM_RECALLIMAGE3: case IDM_RECALLIMAGE4: case IDM_RECALLIMAGE5: case IDM_RECALLIMAGE6: case IDM_RECALLIMAGE7: case IDM_RECALLIMAGE8: case IDM_RECALLIMAGE9: DeactivateTool(); lstrcpy(szFileName, Control.RecallImage[idCmd - IDM_RECALLIMAGE0]); if( OPTION3 && Control.Retail ) DoLowResLoad( 0, szFileName ); else if( OPTION1 && Control.Retail ) PictPubApp.OpenDocumentFileImmediate( szFileName, OM_FASTBITS ); else AstralImageLoadBG( 0, szFileName, YES ); break; case IDM_ALTOPEN: DeactivateTool(); // Command line sent from a second instance prior to it closing /* If the caller passed in a file name, try to load it or print it */ /* if ( !(lpszCmdLine = (LPTR)lParam) ) break; */ HandleCommandLine( hWindow, lpszCmdLine, &bPrint ); break; case PS_SERVICE_ABORT_BEGIN: case PS_SERVICE_ABORT_CHECK: case PS_SERVICE_ABORT_END: case PS_SERVICE_ABORT_BEGIN_NOESC: case PS_SERVICE_BUF_DELETE: case PS_SERVICE_GET_IMAGE_INFO: case PS_SERVICE_PRIVATE_INI: case PS_SERVICE_BUF_ALLOC: case PS_SERVICE_BUF_LOCK1: case PS_SERVICE_BUF_UNLOCK1: case PS_SERVICE_BUF_NEXTLINE: case PS_SERVICE_BUF_LINEPTR: case PS_SERVICE_BUF_LINE_TABLE: return( HandlePluginMessage( lpImage, MDIFrame_wParam, MDIFrame_lParam )); break; case IDM_RUN0: case IDM_RUN1: case IDM_RUN2: case IDM_RUN3: case IDM_RUN4: case IDM_RUN5: case IDM_RUN6: case IDM_RUN7: case IDM_RUN8: case IDM_RUN9: RunTask( hWindow, idCmd, IDS_RUNTASKLIST ); break; case IDM_CLOSEIT: DeactivateTool(); PictPubApp.CloseDocumentFile(lpImage); break; default: return( FALSE ); } return( TRUE ); }
VOID BL_ThreadPoolWorkThread::Run() { if (CheckQuit()) { return; } while (TRUE) { if (CheckQuit()) { CL_BOOL flag = CL_FALSE; m_cSyncObj.SynchronizeStart(); flag = m_cRunTaskList.empty(); m_cSyncObj.SynchronizeEnd(); if (flag) { break; } } while (GetRunTaskCnt() > 0) { m_cSyncObj.SynchronizeStart(); m_pCurrentRunTask = m_cRunTaskList.front(); m_cRunTaskList.pop_front(); m_cSyncObj.SynchronizeEnd(); m_sRunSyncObj.SynchronizeStart(); // Needn't be locked by m_cSyncObj, for the current task point is deleted by this thread. if (m_pCurrentRunTask != NULL) { if (m_pCurrentRunTask->IsCanceled()) { m_pCurrentRunTask->OnAbandon(BL_TASKABANDON_CANCELBYUSER); } else { RunTask(m_pCurrentRunTask); } } m_sRunSyncObj.SynchronizeEnd(); m_dwIdleTimeStamp = ::GetTickCount(); // update group map id map m_sGroupIdMapSyncObj.SynchronizeStart(); if (NULL != m_pCurrentRunTask) { INT nGroupId = m_pCurrentRunTask->GetTaskGroupId(); GroupIdMap::iterator it = m_cGroupIdMap.find(nGroupId); if (it != m_cGroupIdMap.end()) { it->second = it->second - 1; if (0 == it->second) { m_cGroupIdMap.erase(it); } } } m_sGroupIdMapSyncObj.SynchronizeEnd(); m_cSyncObj.SynchronizeStart(); if (NULL != m_pCurrentRunTask) { delete m_pCurrentRunTask; m_pCurrentRunTask = NULL; } m_cSyncObj.SynchronizeEnd(); } // Notify manage thread m_pcManager->Notify(); // Wait for notify if (!m_StopFlag) { Wait(); } } }
bool MessageLoop::DeferOrRunPendingTask(const PendingTask& task) { //TODO(tangjie): add nestable task process. RunTask(task); return true; }