void Sys_Quit( void ) { timeEndPeriod( 1 ); SV_Shutdown( "Server quit\n" ); CL_Shutdown(); if( dedicated && dedicated->integer ) FreeConsole(); // shut down QHOST hooks if necessary DeinitConProc(); Qcommon_Shutdown(); exit( 0 ); }
LC3Sound::~LC3Sound() { /* stop the timer */ timeEndPeriod( 20); timeKillEvent( gwid); lpSwSamp->Stop(); lpSwSamp->Release(); lpSwSamp = NULL; lpDirectSoundBuffer->Stop(); lpDirectSoundBuffer->Release(); lpDirectSound->Release(); lpDirectSound = NULL; free(soundData); }
void Sys_Error (const char *error, ...) { va_list argptr; char text[1024]; va_start (argptr, error); vsnprintf (text, sizeof(text), error, argptr); va_end (argptr); timeEndPeriod( 1 ); CL_Shutdown (); Qcommon_Shutdown (); if (qDedConsole) { MSG msg; BOOL bRet; Conbuf_AppendText( text ); Conbuf_AppendText( "\n" ); Sys_SetErrorText( text ); Sys_ShowConsole( 1, true ); // wait for the user to quit while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) { if (bRet == -1) break; TranslateMessage (&msg); DispatchMessage (&msg); Sleep(25); } } else { MessageBox(NULL, text, "Error", 0 /* MB_OK */ ); } Sys_DestroyConsole(); exit (1); }
/* ================= Sys_Error ================= */ void Sys_Error( const char *error, ... ) { va_list argptr; char string[4096]; #if defined (_WIN32) && !defined (_DEBUG) MSG msg; #endif va_start (argptr,error); idStr::vsnPrintf (string, sizeof(string), error, argptr); va_end (argptr); #if defined (_WIN32) && !defined (_DEBUG) Conbuf_AppendText( string ); Conbuf_AppendText( "\n" ); #else // Print text in the console window/box Sys_Print( string ); Sys_Print( "\n" ); #endif #if defined (_WIN32) && !defined (_DEBUG) Sys_SetErrorText( string ); Sys_ShowConsole( 1, qtrue ); timeEndPeriod( 1 ); IN_Shutdown(); // wait for the user to quit while ( 1 ) { if ( !GetMessage( &msg, NULL, 0, 0 ) ) { Com_Quit_f(); } TranslateMessage( &msg ); DispatchMessage( &msg ); } Sys_DestroyConsole(); #endif CL_Shutdown( ); Sys_ErrorDialog( string ); Sys_Exit( 1 ); }
CBaseReferenceClock::~CBaseReferenceClock() { if (m_TimerResolution) timeEndPeriod(m_TimerResolution); m_pSchedule->DumpLinkedList(); if (m_hThread) { m_bAbort = TRUE; TriggerThread(); WaitForSingleObject( m_hThread, INFINITE ); EXECUTE_ASSERT( CloseHandle(m_hThread) ); m_hThread = 0; EXECUTE_ASSERT( CloseHandle(m_pSchedule->GetEvent()) ); delete m_pSchedule; } }
int sanity_run(struct cpuid_state_t *state) { sanity_handler_t *p = handlers; unsigned int ret = 0; #ifdef TARGET_OS_WINDOWS TIMECAPS tc; timeGetDevCaps(&tc, sizeof(TIMECAPS)); timeBeginPeriod(tc.wPeriodMin); #endif while (*p) { if ((*p++)(state) != 0) ret = p - handlers; } #ifdef TARGET_OS_WINDOWS timeEndPeriod(tc.wPeriodMin); #endif return ret; }
void I_Quit() { HasExited = true; /* Prevent infinitely recursive exits -- killough */ if (TimerEventID != 0) { timeKillEvent(TimerEventID); } if (NewTicArrived != NULL) { CloseHandle(NewTicArrived); } timeEndPeriod(TimerPeriod); if (demorecording) { G_CheckDemoStatus(); } }
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch( ul_reason_for_call ) { case DLL_PROCESS_ATTACH: { // BUG - EXE/DLL Paths - start dllModule = hModule; #ifdef _DEBUG MessageBox(0, "DLL attached", "Message", 0); #endif // BUG - EXE/DLL Paths - end // The DLL is being loaded into the virtual address space of the current process as a result of the process starting up OutputDebugString("DLL_PROCESS_ATTACH\n"); // set timer precision MMRESULT iTimeSet = timeBeginPeriod(1); // set timeGetTime and sleep resolution to 1 ms, otherwise it's 10-16ms FAssertMsg(iTimeSet==TIMERR_NOERROR, "failed setting timer resolution to 1 ms"); } break; case DLL_THREAD_ATTACH: // OutputDebugString("DLL_THREAD_ATTACH\n"); break; case DLL_THREAD_DETACH: // OutputDebugString("DLL_THREAD_DETACH\n"); break; case DLL_PROCESS_DETACH: // BUG - EXE/DLL Paths - start dllModule = NULL; // BUG - EXE/DLL Paths - end OutputDebugString("DLL_PROCESS_DETACH\n"); timeEndPeriod(1); GC.setDLLIFace(NULL); break; } return TRUE; // success }
//============================================================================= // Call repeatedly by the main message loop in WinMain //============================================================================= void Game::run(HWND hwnd) { if(graphics == NULL) // if graphics not initialized return; // calculate elapsed time of last frame, save in frameTime QueryPerformanceCounter(&timeEnd); frameTime = (float)(timeEnd.QuadPart - timeStart.QuadPart ) / (float)timerFreq.QuadPart; // Power saving code, requires winmm.lib // if not enough time has elapsed for desired frame rate if (frameTime < MIN_FRAME_TIME) { sleepTime = (DWORD)((MIN_FRAME_TIME - frameTime)*1000); timeBeginPeriod(1); // Request 1mS resolution for windows timer Sleep(sleepTime); // release cpu for sleepTime timeEndPeriod(1); // End 1mS timer resolution return; } if (frameTime > 0.0) fps = (fps*0.99f) + (0.01f/frameTime); // average fps if (frameTime > MAX_FRAME_TIME) // if frame rate is very slow frameTime = MAX_FRAME_TIME; // limit maximum frameTime timeStart = timeEnd; // update(), ai(), and collisions() are pure virtual functions. // These functions must be provided in the class that inherits from Game. if (!paused) // if not paused { update(); // update all game items ai(); // artificial intelligence collisions(); // handle collisions input->vibrateControllers(frameTime); // handle controller vibration } renderGame(); // draw all game items input->readControllers(); // read state of controllers // Clear input // Call this after all key checks are done input->clear(inputNS::KEYS_PRESSED); }
static void SDL_SetSystemTimerResolution(const UINT uPeriod) { #ifndef __WINRT__ static UINT timer_period = 0; if (uPeriod != timer_period) { if (timer_period) { timeEndPeriod(timer_period); } timer_period = uPeriod; if (timer_period) { timeBeginPeriod(timer_period); } } #endif }
GuiApp::~GuiApp() { //! close simulation exit_main(0); libManager->releaseLibrary("cfg_manager"); libManager->releaseLibrary("lib_manager_gui"); libManager->releaseLibrary("main_gui"); libManager->clearLibraries(); delete libManager; #ifdef WIN32 // end scheduler of 1ms timeEndPeriod(1); #endif //WIN32 }
LOCAL TCALLBACK void hal_close(struct THALBase *hal, struct TTask *task) { struct HALSpecific *hws = hal->hmb_Specific; EnterCriticalSection(&hws->hsp_DevLock); if (hws->hsp_Timer) { if (--hws->hsp_RefCount == 0) { timeKillEvent(hws->hsp_Timer); timeEndPeriod(1); hws->hsp_Timer = TNULL; } } LeaveCriticalSection(&hws->hsp_DevLock); }
void Game::run(HWND hWnd) { if (graphics_ == NULL) // If graphics not initialized { return; } QueryPerformanceCounter(&timeEnd_); frameTime_ = (double)(timeEnd_.QuadPart - timeStart_.QuadPart) / (double)timerFreq_.QuadPart; // if the frame time is less than MIN_FRAME_TIME do idle processing //otherwise run game if (frameTime_ < MIN_FRAME_TIME) { //figure out how long to sleep for sleepTime_ = (DWORD)(MIN_FRAME_TIME - frameTime_) * 1000; timeBeginPeriod(1);// Request 1mS resolution for windows timer Sleep(sleepTime_); // Release CPU for sleepTime timeEndPeriod(1); // End 1mS timer resolution return; } if (frameTime_ > 0.0) { fps_ = (fps_ * .99) + (0.1 / frameTime_); } if (frameTime_ > MAX_FRAME_TIME) { frameTime_ = MAX_FRAME_TIME; } // reset the elapsed time to 0 timeStart_ = timeEnd_; //Pure virtual functions defined by derived Classes update(); // Update all game items renderGame(); //renderGame() draws all items and calls pure virtual function render // Clear input // Call this after all key checks are done input_->clear(InputConstants::KEYS_PRESSED); }
static void gdk_frame_clock_idle_end_updating (GdkFrameClock *clock) { GdkFrameClockIdle *clock_idle = GDK_FRAME_CLOCK_IDLE (clock); GdkFrameClockIdlePrivate *priv = clock_idle->priv; g_return_if_fail (priv->updating_count > 0); priv->updating_count--; maybe_stop_idle (clock_idle); #ifdef G_OS_WIN32 if (priv->updating_count == 0 && priv->begin_period) { timeEndPeriod(1); priv->begin_period = FALSE; } #endif }
double currentTime() { // Use a combination of ftime and QueryPerformanceCounter. // ftime returns the information we want, but doesn't have sufficient resolution. // QueryPerformanceCounter has high resolution, but is only usable to measure time intervals. // To combine them, we call ftime and QueryPerformanceCounter initially. Later calls will use QueryPerformanceCounter // by itself, adding the delta to the saved ftime. We periodically re-sync to correct for drift. static bool started; static double syncLowResUTCTime; static double syncHighResUpTime; static double lastUTCTime; double lowResTime = lowResUTCTime(); if (!qpcAvailable()) return lowResTime / 1000.0; double highResTime = highResUpTime(); if (!syncedTime) { timeBeginPeriod(1); // increase time resolution around low-res time getter syncLowResUTCTime = lowResTime = lowResUTCTime(); timeEndPeriod(1); // restore time resolution syncHighResUpTime = highResTime; syncedTime = true; } double highResElapsed = highResTime - syncHighResUpTime; double utc = syncLowResUTCTime + highResElapsed; // force a clock re-sync if we've drifted double lowResElapsed = lowResTime - syncLowResUTCTime; const double maximumAllowedDriftMsec = 15.625 * 2.0; // 2x the typical low-res accuracy if (fabs(highResElapsed - lowResElapsed) > maximumAllowedDriftMsec) syncedTime = false; // make sure time doesn't run backwards (only correct if difference is < 2 seconds, since DST or clock changes could occur) const double backwardTimeLimit = 2000.0; if (utc < lastUTCTime && (lastUTCTime - utc) < backwardTimeLimit) return lastUTCTime / 1000.0; lastUTCTime = utc; return utc / 1000.0; }
/*===================================================================*/ static void InfoNES_StopTimer() { LOGV("InfoNES_StopTimer"); if ( 0 != uTimerID ) { #ifdef WIN32 TIMECAPS caps; timeKillEvent( uTimerID ); uTimerID = 0; timeGetDevCaps( &caps, sizeof(caps) ); timeEndPeriod( caps.wPeriodMin * TIMER_PER_LINE ); #else timer_delete( uTimerID ); uTimerID = 0; #endif } // Delete Critical Section Object LOGV("InfoNES_StopTimer finished"); }
/* ================ Sys_Quit This function never returns. ================ */ void Sys_Quit(void) { timeEndPeriod(1); #if USE_CLIENT #if USE_SYSCON if (dedicated && dedicated->integer) { FreeConsole(); } #endif #elif USE_WINSVC if (statusHandle && !shouldExit) { shouldExit = SE_YES; Com_AbortFrame(); } #endif exit(0); }
void DirectSoundClose( MADDriverRec* WinMADDriver) { if( WinMADDriver->lpDirectSound) { /* stop the timer */ timeKillEvent( gwID); timeEndPeriod( 20); WinMADDriver->lpSwSamp->lpVtbl->Stop( WinMADDriver->lpSwSamp); WinMADDriver->lpSwSamp->lpVtbl->Release( WinMADDriver->lpSwSamp); WinMADDriver->lpSwSamp = 0L; WinMADDriver->lpDirectSoundBuffer->lpVtbl->Stop(WinMADDriver->lpDirectSoundBuffer); WinMADDriver->lpDirectSoundBuffer->lpVtbl->Release(WinMADDriver->lpDirectSoundBuffer); WinMADDriver->lpDirectSound->lpVtbl->Release( WinMADDriver->lpDirectSound); WinMADDriver->lpDirectSound = NULL; } }
void APIDataReceiver::run() { timeBeginPeriod(1); int lastUpdate = -1; while(!stop) { // wait for new data and copy it into the data buffer, if data is not null if(waitForDataReady(TIMEOUT, data)) { if(header) { // if header changes size, assume a new connection if(!data || dataSize != header->bufLen) { reset(); dataSize = header->bufLen; data = new char[dataSize]; } else if(data) { if(lastUpdate < header->sessionInfoUpdate) { updateStaticInfo(); //TODO: update semi-static data lastUpdate = header->sessionInfoUpdate; } //TODO: update dynamic data } } } else if(!isConnected()) { // session ended reset(); } } reset(); shutdown(); timeEndPeriod(1); }
/* ================= Sys_Error ================= */ void Sys_Error(const char *error, ...) { va_list argptr; char string[1024]; #if defined (USE_WINDOWS_CONSOLE) MSG msg; #endif va_start(argptr, error); Q_vsnprintf(string, sizeof(string), error, argptr); va_end(argptr); #if defined (USE_WINDOWS_CONSOLE) Conbuf_AppendText(string); Conbuf_AppendText("\n"); Sys_Splash(qfalse); Sys_SetErrorText(string); Sys_ShowConsole(1, qtrue); timeEndPeriod(1); IN_Shutdown(); // wait for the user to quit while (1) { if (!GetMessage(&msg, NULL, 0, 0)) { Com_Quit_f(); } TranslateMessage(&msg); DispatchMessage(&msg); } Sys_DestroyConsole(); #endif Sys_ErrorDialog(string); Sys_Exit(3); }
void CALL HGE_Impl::System_Shutdown() { System_Log("\nFinishing.."); timeEndPeriod(1); _ClearQueue(); _SoundDone(); _GfxDone(); if(hwnd) { //ShowWindow(hwnd, SW_HIDE); //SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW); //ShowWindow(hwnd, SW_SHOW); DestroyWindow(hwnd); hwnd=0; } if(hInstance) UnregisterClass(WINDOW_CLASS_NAME, hInstance); System_Log("The End."); }
Rpcs3App::Rpcs3App() { #ifdef _WIN32 timeBeginPeriod(1); WSADATA wsaData; WORD wVersionRequested = MAKEWORD(2, 2); WSAStartup(wVersionRequested, &wsaData); std::atexit([] { timeEndPeriod(1); WSACleanup(); }); #endif #if defined(__unix__) && !defined(__APPLE__) XInitThreads(); #endif }
// Standard DLL loader main BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved) { switch (dwReason) { case DLL_PROCESS_ATTACH: gHInstance = (HINSTANCE)hinstDLL; SetupThunRTMainHook(); timeBeginPeriod(1); break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: timeEndPeriod(1); CleanUp(); break; } return TRUE; }
/* ============================================================================= This routine de-intializes the system timer used for throttling the emulation speed. ============================================================================= */ void deinit_throttle_timer(void) { #ifdef WIN32 /* Kill the timer event */ if (gThrottleId != 0) timeKillEvent(gThrottleId); /* End the timer period */ timeEndPeriod(gThrottlePeriod); /* Destory the triggering event */ CloseHandle(gThrottleEvent); #else /* Instruct the throttle thread to terminate */ gThrottleExit = 1; /* Join our throttle thread to ensure a clean shutdown */ pthread_join(gThrottleThread, NULL); #endif }
/** * Cleans up after system_Init() and system_Configure(). */ void system_End(void) { HWND ipcwindow; /* FIXME: thread-safety... */ if (p_helper) { if( ( ipcwindow = FindWindow( 0, L"VLC ipc "VERSION ) ) != 0 ) { SendMessage( ipcwindow, WM_QUIT, 0, 0 ); } vlc_object_release (p_helper); p_helper = NULL; } timeEndPeriod(5); /* XXX: In theory, we should not call this if WSAStartup() failed. */ WSACleanup(); }
static ULONG WINAPI IDsCaptureDriverNotifyImpl_Release(PIDSDRIVERNOTIFY iface) { IDsCaptureDriverNotifyImpl *This = (IDsCaptureDriverNotifyImpl *)iface; ULONG refCount = InterlockedDecrement(&This->ref); TRACE("(%p) ref was %d\n", This, refCount + 1); if (!refCount) { This->buffer->notify = NULL; if (This->timerID) { timeKillEvent(This->timerID); timeEndPeriod(DS_TIME_RES); } HeapFree(GetProcessHeap(), 0, This->notifies); HeapFree(GetProcessHeap(), 0, This); TRACE("(%p) released\n", This); } return refCount; }
/** Close sockets used * @param[in] port = port context struct * @return 0 */ int ecx_portt::closenic() { timeEndPeriod(15); if (this->sockhandle != NULL) { DeleteCriticalSection(&(this->getindex_mutex)); DeleteCriticalSection(&(this->tx_mutex)); DeleteCriticalSection(&(this->rx_mutex)); pcap_close(this->sockhandle); this->sockhandle = NULL; } if ((this->redport) && (this->redport->sockhandle != NULL)) { pcap_close(this->redport->sockhandle); this->redport->sockhandle = NULL; } return 0; }
static int mm_start_timer(struct qemu_alarm_timer *t) { timeGetDevCaps(&mm_tc, sizeof(mm_tc)); timeBeginPeriod(mm_tc.wPeriodMin); mm_timer = timeSetEvent(mm_tc.wPeriodMin, /* interval (ms) */ mm_tc.wPeriodMin, /* resolution */ mm_alarm_handler, /* function */ (DWORD_PTR)t, /* parameter */ TIME_ONESHOT | TIME_CALLBACK_FUNCTION); if (!mm_timer) { fprintf(stderr, "Failed to initialize win32 alarm timer\n"); timeEndPeriod(mm_tc.wPeriodMin); return -1; } return 0; }
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { const int SAMPLES = 32; DWORD t1[SAMPLES], t2[SAMPLES]; __int64 t3[SAMPLES], t4[SAMPLES], freq3, freq4; TIMECAPS tc; timeGetDevCaps(&tc, sizeof(tc)); timeBeginPeriod(1); QueryPerformanceFrequency((LARGE_INTEGER *) & freq3); freq3 /= 1000; freq4 = MyQueryFrequency(); freq4 /= 1000; for (int i=0; i<SAMPLES; i++) { for (int j=0; j<200; j++) // roughly 0.2 ms to 0.5ms delay DeleteObject(CreateSolidBrush(0)); t1[i] = GetTickCount(); t2[i] = timeGetTime(); QueryPerformanceCounter((LARGE_INTEGER *) & t3[i]); t4[i] = MyQueryCounter(); } timeEndPeriod(1); TCHAR buffer[1024]; sprintf(buffer, _T("tick mm %d Khz %5.1f Mhz %5.1f Mhz\n\n"), tc.wPeriodMin, freq3/1000.0, freq4/1000.0); for (i=0; i<SAMPLES; i++) wsprintf(buffer+ _tcslen(buffer), "%8d %8d %8d %8d\n", (t1[i]-t1[0])*1000000, (t2[i]-t2[0])*1000000, (int)((t3[i]-t3[0])*1000000/freq3), (int)((t4[i]-t4[0])*1000000/freq4)); MyMessageBox(NULL, buffer, "Timer Accuracy", MB_OK); return 0; }
void ofExitCallback(){ // controlled destruction of the mainLoop before // any other deinitialization mainLoop.reset(); // everything should be destroyed here, except for // static objects // finish every library and subsystem #ifndef TARGET_EMSCRIPTEN ofURLFileLoaderShutdown(); #endif #ifndef TARGET_NO_SOUND //------------------------ // try to close engine if needed: ofSoundShutdown(); //------------------------ #endif // try to close quicktime, for non-linux systems: #if defined(OF_VIDEO_CAPTURE_QUICKTIME) || defined(OF_VIDEO_PLAYER_QUICKTIME) closeQuicktime(); #endif //------------------------ // try to close freeImage: ofCloseFreeImage(); #ifdef WIN32_HIGH_RES_TIMING timeEndPeriod(1); #endif // static deinitialization happens after this finishes // every object should have ended by now and won't receive any // events }