void kgmWindow::loop() { m_loop = true; #ifdef WIN32 MSG msg; while(m_wnd && m_loop) { if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { onIdle(); } Sleep(0); } #elif defined(ANDROID) #else XEvent evt; while(m_loop && m_dpy) { while(XPending(m_dpy) > 0) { XNextEvent(m_dpy, &evt); WndProc(this, &evt); if(!m_dpy) return; } if(!m_loop || !m_dpy) break; //else onIdle(); usleep(0); } #endif m_loop = false; }
void DrawingWindow::idleFunction() { onIdle(); //redisplay glutPostRedisplay(); }
int QtEngineThread::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QThread::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: updateTypes((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 1: updateGeometry((*reinterpret_cast< QString(*)>(_a[1]))); break; case 2: updateTime((*reinterpret_cast< QString(*)>(_a[1]))); break; case 3: updateStatus((*reinterpret_cast< QString(*)>(_a[1]))); break; case 4: updateDialog((*reinterpret_cast< Tissue*(*)>(_a[1]))); break; case 5: onLoadDef((*reinterpret_cast< QString(*)>(_a[1]))); break; case 6: onLoadInit((*reinterpret_cast< QString(*)>(_a[1]))); break; case 7: onSetSeed((*reinterpret_cast< int(*)>(_a[1]))); break; case 8: onSetDur((*reinterpret_cast< int(*)>(_a[1]))); break; case 9: onSetUpdate((*reinterpret_cast< int(*)>(_a[1]))); break; case 10: onSetStep((*reinterpret_cast< double(*)>(_a[1]))); break; case 11: onSetView((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QWidget*(*)>(_a[2]))); break; case 12: onWriteHistory((*reinterpret_cast< QString(*)>(_a[1]))); break; case 13: onWriteDetail((*reinterpret_cast< QString(*)>(_a[1]))); break; case 14: toggleRun(); break; case 15: onIdle(); break; default: ; } _id -= 16; } return _id; }
integer ServiceApp::pumpMessages() { /* if(instance->takeOwnership() == false) return -1;*/ timeout = naturalNull; bool go_on = true; while(go_on){ try { natural counter = 0; bool request = instance->anyRequest(); while(!request && onIdle(counter)){ counter++; request = instance->anyRequest(); } const void *req = instance->waitForRequest(timeout); if(req){ go_on = processRequest(req); } else { go_on = !stopCommand; } } catch(const Exception & e){ onWaitException(e); } } return 0; }
void BottomTracker::updateStateMachine(void) { if (!m_active) return; if (!m_got_data) { // Check if we have altitude or depth reference if (m_z_ref.z_units == IMC::Z_NONE) return; // Check if we have a speed reference if (m_dspeed <= 0.0) return; } m_got_data = true; // Run state machine switch (m_mstate) { case SM_IDLE: onIdle(); break; case SM_TRACKING: onTracking(); break; case SM_DEPTH: if (m_args->depth_avoid) onDepth(); else onIdle(); break; case SM_LIMITDEPTH: onLimitDepth(); break; case SM_UNSAFE: onUnsafe(); break; case SM_AVOIDING: onAvoiding(); break; } }
void stage::update_step() { /* Render here */ onIdle(); /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); }
void DrawingWindow::timerFunction(int flag) { clock_t drawStartTime = clock(); onIdle(); glutPostRedisplay(); clock_t drawEndTime = clock(); const int MAX_FPS = 60; unsigned int delayToNextFrame = (CLOCKS_PER_SEC / MAX_FPS) - (drawEndTime - drawStartTime); delayToNextFrame = (unsigned int)(delayToNextFrame + 0.5f); delayToNextFrame < 0 ? delayToNextFrame = 0 : NULL; glutTimerFunc(delayToNextFrame, timerFunction, 0); }
void WorldDrawer3d::idleCallbackFunction(){ unsigned int diff = getTimeDifference(); // Limit to 50 frames per second if (diff >= 20) { tick += diff; onIdle(); //redisplay glutPostRedisplay(); } }
void onKeyboard(unsigned char key, int x, int y) { if (gameOver) return; if (key == 'd') glutPostRedisplay(); // d beture rajzold ujra a kepet working = true; //lift iranyitasanak kezelese if (key == 'q') { if (lift1.moveUp()) { greenWorm.moveUp(lift1); redWorm.moveUp(lift1); } } if (key == 'a') { if (lift1.moveDown()) { greenWorm.checkKilled(lift1); redWorm.checkKilled(lift1); greenWorm.moveDown(lift1); redWorm.moveDown(lift1); } } if (key == 'o') { if (lift2.moveUp()) { greenWorm.moveUp(lift2); redWorm.moveUp(lift2); } } if (key == 'l') { if (lift2.moveDown()) { greenWorm.checkKilled(lift2); redWorm.checkKilled(lift2); greenWorm.moveDown(lift2); redWorm.moveDown(lift2); } } onIdle(); working = false; glutPostRedisplay(); }
int GWMain::messageLoop() { while (processMessage()) { if (checkFocus) { HWND window = GetForegroundWindow(); if (window) { DWORD wndProcessId; GetWindowThreadProcessId(window, &wndProcessId); foreground = (wndProcessId == processId); if (!foreground) // We're in the background, go to sleep until something // interesting happens... MsgWaitForMultipleObjects(0, NULL, false, nonfocusTimeout, QS_ALLINPUT); } } onIdle(); } onExit(); return exitCode; }
void WorldDrawer2d::idleCallbackFunction(){ //call client function onIdle(); //redisplay glutPostRedisplay(); }
int CAppWin32::run() { if (!onCreate()) return 0; int doIdle = 1; int idleCount = 0; int ret; MSG msg; for (;;) { while (doIdle && !PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!onIdle(idleCount++)) doIdle = 0; } ret = GetMessage(&msg, NULL, 0, 0); if (ret == -1) // error, don't process continue; else if (!ret) // WM_QUIT, exit message loop break; TranslateMessage(&msg); DispatchMessage(&msg); switch (msg.message) { // These messages should NOT cause idle processing case WM_MOUSEMOVE: case WM_NCMOUSEMOVE: case WM_PAINT: case 0x0118: // WM_SYSTIMER (caret blink) break; default: //crr add //在IGlobalClient.h里定义 // enum // { // WM_BACK_TO_SELECT_SERVER = WM_USER + 0, // WM_BACK_TO_RE_LOGIN = WM_USER + 1, //将来策划可能要求转到登录界面 // WM_BACK_TO_SELECT_ACTOR = WM_USER + 2, // }; //为避免耦合,这里直接使用>= WM_USER作为判断 if (msg.message >= WM_USER) { break; } doIdle = TRUE; idleCount = 0; break; } } /* MSG msg; while(true) { if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (msg.message == WM_QUIT) break; if (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else { fclDispatchTrace(); onIdle(); } }*/ onClose(); return 0; }
void SocketReactor::run() { _pThread = Thread::current(); Socket::SocketList readable; Socket::SocketList writable; Socket::SocketList except; while (!_stop) { try { readable.clear(); writable.clear(); except.clear(); int nSockets = 0; { FastMutex::ScopedLock lock(_mutex); for (EventHandlerMap::iterator it = _handlers.begin(); it != _handlers.end(); ++it) { if (it->second->accepts(_pReadableNotification)) { readable.push_back(it->first); nSockets++; } if (it->second->accepts(_pWritableNotification)) { writable.push_back(it->first); nSockets++; } if (it->second->accepts(_pErrorNotification)) { except.push_back(it->first); nSockets++; } } } if (nSockets == 0) { onIdle(); Thread::trySleep(static_cast<long>(_timeout.totalMilliseconds())); } else if (Socket::select(readable, writable, except, _timeout)) { onBusy(); for (Socket::SocketList::iterator it = readable.begin(); it != readable.end(); ++it) dispatch(*it, _pReadableNotification); for (Socket::SocketList::iterator it = writable.begin(); it != writable.end(); ++it) dispatch(*it, _pWritableNotification); for (Socket::SocketList::iterator it = except.begin(); it != except.end(); ++it) dispatch(*it, _pErrorNotification); } else onTimeout(); } catch (Exception& exc) { ErrorHandler::handle(exc); } catch (std::exception& exc) { ErrorHandler::handle(exc); } catch (...) { ErrorHandler::handle(); } } onShutdown(); }
LRESULT CALLBACK WindowsWindow::dispatch( const HWND hWnd , const UINT message , const WPARAM wParam , const LPARAM lParam) { assert(!m_hWnd || hWnd == m_hWnd); if (!m_hWnd) return DefWindowProc(hWnd, message, wParam, lParam); // Windows Messages: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx#windows_messages switch (message) { case WM_QUIT: case WM_CLOSE: onClose(); break; case WM_DESTROY: onDestroy(); break; case WM_SIZE: onResize(LOWORD(lParam), HIWORD(lParam)); break; case WM_PAINT: onRepaint(); break; case WM_USER_IDLE: onIdle(); break; case WM_KEYDOWN: case WM_SYSKEYDOWN: if(!onKeyPress(LOWORD(wParam))) DefWindowProc(hWnd, message, wParam, lParam); break; case WM_KEYUP: case WM_SYSKEYUP: if(!onKeyRelease(LOWORD(wParam))) DefWindowProc(hWnd, message, wParam, lParam); break; //case WM_ACTIVATE: // // Check for minimization. // if (!HIWORD(wParam)) // m_eventHandler->activateEvent(); // else // m_eventHandler->minimizeEvent(); // break; case WM_SYSCOMMAND: // Absorb some system commands. switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void WxWindow::processIdle(wxIdleEvent& event) { onIdle(); //event.RequestMore(); }
void NetworkService::handleIdle() { if(onIdle()) startTimer(); }
bool FastThread::threadLoop() { for (;;) { // either nanosleep, sched_yield, or busy wait if (sleepNs >= 0) { if (sleepNs > 0) { ALOG_ASSERT(sleepNs < 1000000000); const struct timespec req = {0, sleepNs}; nanosleep(&req, NULL); } else { sched_yield(); } } // default to long sleep for next cycle sleepNs = FAST_DEFAULT_NS; // poll for state change const FastThreadState *next = poll(); if (next == NULL) { // continue to use the default initial state until a real state is available // FIXME &initial not available, should save address earlier //ALOG_ASSERT(current == &initial && previous == &initial); next = current; } command = next->mCommand; if (next != current) { // As soon as possible of learning of a new dump area, start using it dumpState = next->mDumpState != NULL ? next->mDumpState : mDummyDumpState; logWriter = next->mNBLogWriter != NULL ? next->mNBLogWriter : &dummyLogWriter; setLog(logWriter); // We want to always have a valid reference to the previous (non-idle) state. // However, the state queue only guarantees access to current and previous states. // So when there is a transition from a non-idle state into an idle state, we make a // copy of the last known non-idle state so it is still available on return from idle. // The possible transitions are: // non-idle -> non-idle update previous from current in-place // non-idle -> idle update previous from copy of current // idle -> idle don't update previous // idle -> non-idle don't update previous if (!(current->mCommand & FastThreadState::IDLE)) { if (command & FastThreadState::IDLE) { onIdle(); oldTsValid = false; #ifdef FAST_MIXER_STATISTICS oldLoadValid = false; #endif ignoreNextOverrun = true; } previous = current; } current = next; } #if !LOG_NDEBUG next = NULL; // not referenced again #endif dumpState->mCommand = command; // << current, previous, command, dumpState >> switch (command) { case FastThreadState::INITIAL: case FastThreadState::HOT_IDLE: sleepNs = FAST_HOT_IDLE_NS; continue; case FastThreadState::COLD_IDLE: // only perform a cold idle command once // FIXME consider checking previous state and only perform if previous != COLD_IDLE if (current->mColdGen != coldGen) { int32_t *coldFutexAddr = current->mColdFutexAddr; ALOG_ASSERT(coldFutexAddr != NULL); int32_t old = android_atomic_dec(coldFutexAddr); if (old <= 0) { syscall(__NR_futex, coldFutexAddr, FUTEX_WAIT_PRIVATE, old - 1, NULL); } int policy = sched_getscheduler(0); if (!(policy == SCHED_FIFO || policy == SCHED_RR)) { ALOGE("did not receive expected priority boost"); } // This may be overly conservative; there could be times that the normal mixer // requests such a brief cold idle that it doesn't require resetting this flag. isWarm = false; measuredWarmupTs.tv_sec = 0; measuredWarmupTs.tv_nsec = 0; warmupCycles = 0; sleepNs = -1; coldGen = current->mColdGen; #ifdef FAST_MIXER_STATISTICS bounds = 0; full = false; #endif oldTsValid = !clock_gettime(CLOCK_MONOTONIC, &oldTs); timestampStatus = INVALID_OPERATION; } else { sleepNs = FAST_HOT_IDLE_NS; } continue; case FastThreadState::EXIT: onExit(); return false; default: LOG_ALWAYS_FATAL_IF(!isSubClassCommand(command)); break; } // there is a non-idle state available to us; did the state change? if (current != previous) { onStateChange(); #if 1 // FIXME shouldn't need this // only process state change once previous = current; #endif } // do work using current state here attemptedWrite = false; onWork(); // To be exactly periodic, compute the next sleep time based on current time. // This code doesn't have long-term stability when the sink is non-blocking. // FIXME To avoid drift, use the local audio clock or watch the sink's fill status. struct timespec newTs; int rc = clock_gettime(CLOCK_MONOTONIC, &newTs); if (rc == 0) { //logWriter->logTimestamp(newTs); if (oldTsValid) { time_t sec = newTs.tv_sec - oldTs.tv_sec; long nsec = newTs.tv_nsec - oldTs.tv_nsec; ALOGE_IF(sec < 0 || (sec == 0 && nsec < 0), "clock_gettime(CLOCK_MONOTONIC) failed: was %ld.%09ld but now %ld.%09ld", oldTs.tv_sec, oldTs.tv_nsec, newTs.tv_sec, newTs.tv_nsec); if (nsec < 0) { --sec; nsec += 1000000000; } // To avoid an initial underrun on fast tracks after exiting standby, // do not start pulling data from tracks and mixing until warmup is complete. // Warmup is considered complete after the earlier of: // MIN_WARMUP_CYCLES write() attempts and last one blocks for at least warmupNs // MAX_WARMUP_CYCLES write() attempts. // This is overly conservative, but to get better accuracy requires a new HAL API. if (!isWarm && attemptedWrite) { measuredWarmupTs.tv_sec += sec; measuredWarmupTs.tv_nsec += nsec; if (measuredWarmupTs.tv_nsec >= 1000000000) { measuredWarmupTs.tv_sec++; measuredWarmupTs.tv_nsec -= 1000000000; } ++warmupCycles; if ((nsec > warmupNs && warmupCycles >= MIN_WARMUP_CYCLES) || (warmupCycles >= MAX_WARMUP_CYCLES)) { isWarm = true; dumpState->mMeasuredWarmupTs = measuredWarmupTs; dumpState->mWarmupCycles = warmupCycles; } } sleepNs = -1; if (isWarm) { if (sec > 0 || nsec > underrunNs) { ATRACE_NAME("underrun"); // FIXME only log occasionally ALOGV("underrun: time since last cycle %d.%03ld sec", (int) sec, nsec / 1000000L); dumpState->mUnderruns++; ignoreNextOverrun = true; } else if (nsec < overrunNs) { if (ignoreNextOverrun) { ignoreNextOverrun = false; } else { // FIXME only log occasionally ALOGV("overrun: time since last cycle %d.%03ld sec", (int) sec, nsec / 1000000L); dumpState->mOverruns++; } // This forces a minimum cycle time. It: // - compensates for an audio HAL with jitter due to sample rate conversion // - works with a variable buffer depth audio HAL that never pulls at a // rate < than overrunNs per buffer. // - recovers from overrun immediately after underrun // It doesn't work with a non-blocking audio HAL. sleepNs = forceNs - nsec; } else { ignoreNextOverrun = false; } } #ifdef FAST_MIXER_STATISTICS if (isWarm) { // advance the FIFO queue bounds size_t i = bounds & (dumpState->mSamplingN - 1); bounds = (bounds & 0xFFFF0000) | ((bounds + 1) & 0xFFFF); if (full) { bounds += 0x10000; } else if (!(bounds & (dumpState->mSamplingN - 1))) { full = true; } // compute the delta value of clock_gettime(CLOCK_MONOTONIC) uint32_t monotonicNs = nsec; if (sec > 0 && sec < 4) { monotonicNs += sec * 1000000000; } // compute raw CPU load = delta value of clock_gettime(CLOCK_THREAD_CPUTIME_ID) uint32_t loadNs = 0; struct timespec newLoad; rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &newLoad); if (rc == 0) { if (oldLoadValid) { sec = newLoad.tv_sec - oldLoad.tv_sec; nsec = newLoad.tv_nsec - oldLoad.tv_nsec; if (nsec < 0) { --sec; nsec += 1000000000; } loadNs = nsec; if (sec > 0 && sec < 4) { loadNs += sec * 1000000000; } } else { // first time through the loop oldLoadValid = true; } oldLoad = newLoad; } #ifdef CPU_FREQUENCY_STATISTICS // get the absolute value of CPU clock frequency in kHz int cpuNum = sched_getcpu(); uint32_t kHz = tcu.getCpukHz(cpuNum); kHz = (kHz << 4) | (cpuNum & 0xF); #endif // save values in FIFO queues for dumpsys // these stores #1, #2, #3 are not atomic with respect to each other, // or with respect to store #4 below dumpState->mMonotonicNs[i] = monotonicNs; dumpState->mLoadNs[i] = loadNs; #ifdef CPU_FREQUENCY_STATISTICS dumpState->mCpukHz[i] = kHz; #endif // this store #4 is not atomic with respect to stores #1, #2, #3 above, but // the newest open & oldest closed halves are atomic with respect to each other dumpState->mBounds = bounds; ATRACE_INT("cycle_ms", monotonicNs / 1000000); ATRACE_INT("load_us", loadNs / 1000); } #endif } else { // first time through the loop oldTsValid = true; sleepNs = periodNs; ignoreNextOverrun = true; } oldTs = newTs; } else { // monotonic clock is broken oldTsValid = false; sleepNs = periodNs; } } // for (;;) // never return 'true'; Thread::_threadLoop() locks mutex which can result in priority inversion }
void onDisplay( ) { glClearColor(0.2f, 0.2f, 0.2f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (currentCur != NULL) { glLineWidth(8); glClearColor(0.2f, 0.2f, 0.2f, 1.0f); glPointSize(9); glColor3d(1,1,1); currentCur->drawControlPoints(); onIdle(); currentCur->draw(.2,.6,1); } glColor3d(1,1,1); glLineWidth(3); glPointSize(6); // defalt setting if (!LC.empty()) { for (int i = 0; i < LC.size(); i++) drawCurve(LC.at(i)); } if(!BC.empty()) { for(int i = 0; i < BC.size(); i++) drawCurve(BC.at(i)); } if(!PL.empty()) { for(int i = 0; i < PL.size(); i++) drawCurve(PL.at(i)); } if(!CC.empty()) { for(int i = 0; i < CC.size(); i++) drawCurve(CC.at(i)); } if(!CR.empty()) { for(int i = 0; i < CR.size(); i++) drawCurve(CR.at(i)); } int NoC = (int) Curves.size(); std::vector<int> stack; while (NoC > 0) { stack.push_back(NoC % 10); NoC = NoC/10; } int shift = 0; if(stack.empty()) BezierZero(shift); // For the Bezier curve counter while(!stack.empty()) { int n = stack.back(); stack.pop_back(); switch (n) { case 0: BezierZero(shift); break; case 1: BezierOne(shift); break; case 2: BezierTwo(shift); break; case 3: BezierThree(shift); break; case 4: BezierFour(shift); break; case 5: BezierFive(shift); break; case 6: BezierSix(shift); break; case 7: BezierSeven(shift); break; case 8: BezierEight(shift); break; case 9: BezierNine(shift); break; default: break; } shift +=1; } glutSwapBuffers(); }
void Preview::_connect() { QTimer * t = new QTimer(); connect(t, SIGNAL(timeout()), this, SLOT(onIdle())); t->start(0); }