void dgWorld::RunStep () { static int zzzz; if (zzzz == 50) { DG_START_RECORDING("../../../../sdk/dProfiler/xxxx.tt"); } if (zzzz == 500) { DG_STOP_RECORDING(); } zzzz++; DG_TRACKTIME(__FUNCTION__); dgUnsigned64 timeAcc = dgGetTimeInMicrosenconds(); dgFloat32 step = m_savetimestep / m_numberOfSubsteps; for (dgUnsigned32 i = 0; i < m_numberOfSubsteps; i ++) { dgInterlockedExchange(&m_delayDelateLock, 1); StepDynamics (step); dgInterlockedExchange(&m_delayDelateLock, 0); dgDeadBodies& bodyList = *this; dgDeadJoints& jointList = *this; jointList.DestroyJoints (*this); bodyList.DestroyBodies (*this); } const dgBodyMasterList* const masterList = this; dgBodyMasterList::dgListNode* node = masterList->GetFirst(); const dgInt32 threadsCount = GetThreadCount(); for (dgInt32 i = 0; i < threadsCount; i++) { QueueJob(UpdateTransforms, this, node, "dgWorld::UpdateTransforms"); node = node ? node->GetNext() : NULL; } SynchronizationBarrier(); if (m_postUpdateCallback) { m_postUpdateCallback (this, m_savetimestep); } m_lastExecutionTime = (dgGetTimeInMicrosenconds() - timeAcc) * dgFloat32 (1.0e-6f); if (!m_concurrentUpdate) { m_mutex.Release(); } }
void dgWorld::ExecuteUserJob (dgWorkerThreadTaskCallback userJobKernel, void* const userJobKernelContext, const char* const functionName) { QueueJob (userJobKernel, this, userJobKernelContext, functionName); }
void dgWorld::ExecuteUserJob (dgWorkerThreadTaskCallback userJobKernel, void* const userJobKernelContext) { QueueJob (userJobKernel, this, userJobKernelContext); }
/*>int main(int argc, char **argv) ------------------------------- *//** Main program - 16.10.15 Original By: ACRM */ int main(int argc, char **argv) { BOOL runDaemon = FALSE, listJobs = FALSE; int progArg = (-1), verbose = 0, jobInfoID = 0, sleepTime = DEF_POLLTIME, maxWait = DEF_WAITTIME; char queueDir[MAXBUFF]; uid_t uid; gid_t gid; if(ParseCmdLine(argc, argv, &runDaemon, &progArg, &sleepTime, &verbose, queueDir, &maxWait, &listJobs, &jobInfoID)) { char lockFullFile[MAXBUFF]; sprintf(lockFullFile, "%s/%s", queueDir, LOCKFILE); MakeDirectory(queueDir); if(runDaemon) { if(!IsRootUser(&uid, &gid)) { Message(PROGNAME, MSG_FATAL, "With -run, the program must be run as root."); } unlink(lockFullFile); SpawnJobRunner(queueDir, sleepTime, verbose); } else if (listJobs) { ListJobs(queueDir, verbose); } else if(jobInfoID) { CountdownJob(queueDir, jobInfoID, sleepTime); } else { int nJobs, jobID; char msg[MAXBUFF]; if(IsRootUser(&uid, &gid)) { Message(PROGNAME, MSG_FATAL, "Jobs may not be submitted by root"); } jobID = QueueJob(queueDir, lockFullFile, argv+progArg, argc-progArg, maxWait, &nJobs); sprintf(msg, "Submitted job id: %d", jobID); Message(PROGNAME, MSG_INFO, msg); if(verbose) { sprintf(msg, "There are now %d jobs in the queue", nJobs); Message(PROGNAME, MSG_INFO, msg); } } } else { UsageDie(); } return(0); }
UINT WINAPI TimerThread(LPVOID lpVoid) { LPTIMER lpTimer, lpNTimer; UINT64 ui64; DWORD dwResult, dwSleep, dwShift; dwSleep = INFINITE; dwResult = WAIT_OBJECT_0; // Infinite loop for (;;) { EnterCriticalSection(&csIoTimer); if (dwTimerListItems) { TimerGetTickCount(&ui64); //z 处理已过约定时间的 timer if (ui64 >= lpTimerList[0]->ui64DueTime) { dwShift = 0; do { lpTimer = lpTimerList[dwShift++]; for (; lpTimer; lpTimer = lpNTimer) { lpNTimer = lpTimer->lpNext; // Queue timer to external thread if (InterlockedExchange(&lpTimer->lStatus, TIMER_QUEUED) == TIMER_WAIT) { QueueJob(ExecTimer, lpTimer, JOB_PRIORITY_HIGH); } } TimerGetTickCount(&ui64); } while (--dwTimerListItems && ui64 >= lpTimerList[dwShift]->ui64DueTime); //z 将剩下的timer向前移动 MoveMemory(lpTimerList, &lpTimerList[dwShift], dwTimerListItems * sizeof(LPTIMER)); //z 如果队列中还有剩余的 timer if (dwTimerListItems) { //z 计算到下次 timer 到达时间还得多久 dwSleep = (DWORD)(lpTimerList[0]->ui64DueTime <= ui64 ? 0 : lpTimerList[0]->ui64DueTime - ui64); } else dwSleep = INFINITE; } else dwSleep = (DWORD)(lpTimerList[0]->ui64DueTime <= ui64 ? 0 : lpTimerList[0]->ui64DueTime - ui64); } else dwSleep = INFINITE; // Cancel waitable timer //z 对数组处理完毕 LeaveCriticalSection(&csIoTimer); //z 使用这个避免了不必要的循环(从而不需要消耗cpu时间) WaitForSingleObject(hTimerUpdate, dwSleep); //z 查看 dwDaemonStatus,查看是否为 shutdown 状态 if (dwDaemonStatus == DAEMON_SHUTDOWN) { break; } } //z dwDaemonStatus InterlockedExchange(&lTimerShutdownLock, TRUE); // Exit from this thread CloseHandle(hTimerUpdate); Free(lpTimerList); DeleteCriticalSection(&csIoTimer); ExitThread(0); return FALSE; }