int myTimer(HANDLE hTimerQueue) { HANDLE hTimer = NULL; // Use an event object to track the TimerRoutine execution gDoneEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (NULL == gDoneEvent) { printf("CreateEvent failed (%d)\n", GetLastError()); return 1; } // Create the timer queue. hTimerQueue = CreateTimerQueue(); if (NULL == hTimerQueue) { printf("CreateTimerQueue failed (%d)\n", GetLastError()); return 2; } // Set a timer to call the timer routine in 10 seconds. int arg = 123; if (!CreateTimerQueueTimer(&hTimer, hTimerQueue, (WAITORTIMERCALLBACK)TimerRoutine, &arg, 10000, 10000, 0)) { printf("CreateTimerQueueTimer failed (%d)\n", GetLastError()); return 3; } }
// Subclass QProgressDialog() MyQProgressDialog::MyQProgressDialog(LPCSTR titleText, LPCSTR labelText, LPCSTR styleSheet, LPCSTR icon) : QProgressDialog(labelText, CANCEL, 0, 100, QApplication::activeWindow(), 0), m_isCanceled(FALSE), m_indeterminateMode(FALSE), m_lastProgress(-1), m_hMouseHook(NULL), m_hWinHook(NULL), m_hTimerQueue(NULL), m_hUpdateTimer(NULL) { setWindowTitle(titleText); setAutoReset(FALSE); setAutoClose(FALSE); setWindowModality(Qt::WindowModal); setFixedSize(DAILOG_WIDTH, DAILOG_HEIGHT); setSizeGripEnabled(FALSE); // Qt::Tool -- Smaller title bar with smaller 'X' // Qt::Popup -- Boarderless // Qt::SubWindow -- Nonmodal on top with no background //setWindowFlags(Qt::Tool); // Nix the title bar help button setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) | Qt::WindowMinimizeButtonHint); // This time must elapse before dialog shows (default 4sec) setMinimumDuration(SHOW_DELAY); // Set dialog font (and children inherit) QFont fnt(FONT, 10, QFont::Normal); fnt.setStyleStrategy(QFont::PreferAntialias); setFont(fnt); // Put the progress text in the middle if (QProgressBar *bar = findChild<QProgressBar *>()) bar->setAlignment(Qt::AlignCenter); // Optionally set Qt style sheet if (styleSheet && styleSheet[0]) { // From a file? if (strncmp(styleSheet, "url(", 4) == 0) { QString fn(styleSheet + (sizeof("url(") - 1)); fn.chop(1); QFile f(fn); if (f.open(QFile::ReadOnly | QFile::Text)) setStyleSheet(QTextStream(&f).readAll()); } else // No, string setStyleSheet(styleSheet); } // Optionally set titlebar icon if (icon && icon[0]) setWindowIcon(QIcon(icon)); // Progress 0 for the control to setup internally setValue(0); // Start update interval timer if (m_hTimerQueue = CreateTimerQueue()) CreateTimerQueueTimer(&m_hUpdateTimer, m_hTimerQueue, (WAITORTIMERCALLBACK)timerTick, NULL, TARGET_UPDATE_MS, TARGET_UPDATE_MS, 0); _ASSERT(m_hUpdateTimer != NULL); }
CStressManager::CStressManager() { ASockIOInit(); A_MUTEX_INIT(&m_mtxLocker); m_nIDSeq = 0; _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); m_hTimerQueue = CreateTimerQueue(); }
int TestSynchTimerQueue(int argc, char* argv[]) { int index; HANDLE hTimerQueue; HANDLE hTimers[TIMER_COUNT]; APC_DATA apcData[TIMER_COUNT]; g_Event = CreateEvent(NULL, TRUE, FALSE, NULL); hTimerQueue = CreateTimerQueue(); if (!hTimerQueue) { printf("CreateTimerQueue failed (%d)\n", (int) GetLastError()); return -1; } for (index = 0; index < TIMER_COUNT; index++) { apcData[index].TimerId = index; apcData[index].StartTime = GetTickCount(); apcData[index].DueTime = (index * 100) + 500; apcData[index].Period = 1000; apcData[index].FireCount = 0; if (!CreateTimerQueueTimer(&hTimers[index], hTimerQueue, (WAITORTIMERCALLBACK) TimerRoutine, &apcData[index], apcData[index].DueTime, apcData[index].Period, 0)) { printf("CreateTimerQueueTimer failed (%d)\n", (int) GetLastError()); return -1; } } if (WaitForSingleObject(g_Event, INFINITE) != WAIT_OBJECT_0) { printf("WaitForSingleObject failed (%d)\n", (int) GetLastError()); return -1; } for (index = 0; index < TIMER_COUNT; index++) { if (!DeleteTimerQueueTimer(hTimerQueue, hTimers[index], NULL)) { printf("DeleteTimerQueueTimer failed (%d)\n", (int) GetLastError()); return -1; } } if (!DeleteTimerQueue(hTimerQueue)) { printf("DeleteTimerQueue failed (%d)\n", (int) GetLastError()); return -1; } CloseHandle(g_Event); return 0; }
void setSharedTimerFireInterval(double interval) { ASSERT(sharedTimerFiredFunction); unsigned intervalInMS; interval *= 1000; if (interval > USER_TIMER_MAXIMUM) intervalInMS = USER_TIMER_MAXIMUM; else intervalInMS = static_cast<unsigned>(interval); initializeOffScreenTimerWindow(); bool timerSet = false; #if !OS(WINCE) if (Settings::shouldUseHighResolutionTimers()) { if (interval < highResolutionThresholdMsec) { if (!highResTimerActive) { highResTimerActive = true; timeBeginPeriod(timerResolution); } SetTimer(timerWindowHandle, endHighResTimerID, stopHighResTimerInMsec, 0); } DWORD queueStatus = LOWORD(GetQueueStatus(QS_PAINT | QS_MOUSEBUTTON | QS_KEY | QS_RAWINPUT)); // Win32 has a tri-level queue with application messages > user input > WM_PAINT/WM_TIMER. // If the queue doesn't contains input events, we use a higher priorty timer event posting mechanism. if (!(queueStatus & (QS_MOUSEBUTTON | QS_KEY | QS_RAWINPUT))) { if (intervalInMS < USER_TIMER_MINIMUM && !processingCustomTimerMessage && !(queueStatus & QS_PAINT)) { // Call PostMessage immediately if the timer is already expired, unless a paint is pending. // (we prioritize paints over timers) if (InterlockedIncrement(&pendingTimers) == 1) PostMessage(timerWindowHandle, timerFiredMessage, 0, 0); timerSet = true; } else { // Otherwise, delay the PostMessage via a CreateTimerQueueTimer if (!timerQueue) timerQueue = CreateTimerQueue(); if (timer) DeleteTimerQueueTimer(timerQueue, timer, 0); timerSet = CreateTimerQueueTimer(&timer, timerQueue, queueTimerProc, 0, intervalInMS, 0, WT_EXECUTEINTIMERTHREAD | WT_EXECUTEONLYONCE); } } } #endif // !OS(WINCE) if (timerSet) { if (timerID) { KillTimer(timerWindowHandle, timerID); timerID = 0; } } else { timerID = SetTimer(timerWindowHandle, sharedTimerID, intervalInMS, 0); timer = 0; } }
NeoTimer::NeoTimer(): m_hTimerQueue(INVALID_HANDLE_VALUE) { m_hTimerQueue = CreateTimerQueue(); if (NULL == m_hTimerQueue) { printf("CreateTimerQueue failed (%d)\n", GetLastError()); return; } }
void initTicker (Time interval, TickProc handle_tick) { tick_interval = interval; tick_proc = handle_tick; timer_queue = CreateTimerQueue(); if (timer_queue == NULL) { sysErrorBelch("CreateTimerQueue"); stg_exit(EXIT_FAILURE); } }
VCOS_STATUS_T vcos_timer_init(void) { if (timer_queue != NULL) { vcos_assert(0); return VCOS_EEXIST; } timer_queue = CreateTimerQueue(); if (!timer_queue) return VCOS_ENOMEM; return VCOS_SUCCESS; }
void SetTimer(int Seconds) { if (!TimerQueue) { TimerQueue = CreateTimerQueue(); if (!TimerQueue) { Printf("libFuzzer: CreateTimerQueue failed.\n"); exit(1); } } HANDLE Timer; if (!CreateTimerQueueTimer(&Timer, TimerQueue, AlarmHandler, NULL, Seconds*1000, Seconds*1000, 0)) { Printf("libFuzzer: CreateTimerQueueTimer failed.\n"); exit(1); } };
void nglTimer::InitMainTimer() { if (!WM_NGLTIMER) { WM_NGLTIMER = RegisterWindowMessage(_T("nglTimerMessage")); } if (mTimerQueueHandle == NULL) { mTimerQueueHandle = CreateTimerQueue(); NGL_ASSERT(mTimerQueueHandle); BOOL res = CreateTimerQueueTimer(&mTimerHandle, mTimerQueueHandle, TimeProc, NULL, 1, 1, WT_EXECUTEINUITHREAD); NGL_ASSERT(res); } }
ExeTask::ExeTask(RemoteCLI* svr, ExeTaskTreeNode* parent, std::string workName, int nameLine, std::string bhvname, RFSMtask* task, ModelBinder* tmPlugin, int exeType, int callstmtLine, unsigned int tp) :ExeTaskTreeNode(parent, svr, workName, nameLine, task->getBlockID(), task->getFileName(), callstmtLine, tp) { m_tmPlugin = tmPlugin; m_task = task; m_startBehavior = bhvname; m_behaviorTAB = NULL; m_connTAB = NULL; // m_outModelTAB = new ValueMap(); m_wVarTAB = new ValueMap(); m_monitorOff = true; m_monCount = 0; std::string logName("ExeTask-"); logName.append(workName); if(TaskConfig::getIsTaskLog()){ m_logFile = new LogFile((char*)(logName.c_str()), TaskConfig::getLogSize()); m_logFile->setLevel( Log::LOG_LEVEL_DEBUG, true); m_logFile->setLevel( Log::LOG_LEVEL_TRACE, true); m_logFile->setLevel( Log::LOG_LEVEL_ERROR, true); } else{ m_logFile = NULL; } pthread_cond_init(&m_SLEEPstmt_wakeup_cond, NULL); pthread_mutex_init(&m_SLEEPstmt_wakeup_mu, NULL); m_runner = new TaskRunner(this, tmPlugin, m_logFile); if(exeType == DEBUG){ m_runner->setAsDebugMode(); } else if(exeType == MONITOR){ m_runner->setAsMonitorMode(); } //이걸 여기서 초기화 하는 것은 LogFile 매개변수 전달 때문이다. //if(m_tmPlugin->isSimul()) m_tmPlugin->initSimul(m_logFile); m_running = false; #ifdef _WIN32 m_TimerQueue = CreateTimerQueue(); #endif }
static void initTimer( HANDLE gDoneEvent ) { HANDLE hTimer = NULL; HANDLE hTimerQueue = NULL; int arg = 123; // Use an event object to track the TimerRoutine execution gDoneEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); if ( ! gDoneEvent ) { printf( "CreateEvent failed (%d)\n", GetLastError() ); // return 1; } // Create the timer queue. hTimerQueue = CreateTimerQueue(); if ( ! hTimerQueue ) { printf( "CreateTimerQueue failed (%d)\n", GetLastError() ); // return 2; } // Set a timer to call the timer routine in 10 seconds. if ( ! CreateTimerQueueTimer( &hTimer, hTimerQueue, (WAITORTIMERCALLBACK)&StandardTimer::check, &gDoneEvent , TIMEDELTA, TIMEDELTA, 0 ) ) { printf( "CreateTimerQueueTimer failed (%d)\n", GetLastError() ); // return 3; } // TODO: Do other useful work here printf( "Call timer routine in 10 seconds...\n" ); // // Wait for the timer-queue thread to complete using an event // // object. The thread will signal the event at that time. // if (WaitForSingleObject(gDoneEvent, INFINITE) != WAIT_OBJECT_0) // printf("WaitForSingleObject failed (%d)\n", GetLastError()); // // Delete all timers in the timer queue. // if (!DeleteTimerQueue(hTimerQueue)) // printf("DeleteTimerQueue failed (%d)\n", GetLastError()); }
static void *timer_alloc(void (*fn)(void *), void *arg) { struct timer *t; t = malloc(sizeof(*t)); if (!t) return NULL; t->queue = CreateTimerQueue(); if (!t->queue) { free(t); return NULL; } t->callback = fn; t->arg = arg; return t; }
LRESULT ArtWindow::OnCreate(LPCREATESTRUCT) { RECT rc; GetClientRect(&rc); renderer = new RendererGL(GetDC(), rc); //KillTimer(TIMER_REPAINT); //SetTimer(TIMER_REPAINT, 15); if (RepaintTimer) DeleteTimerQueueTimer(TimerQueue, RepaintTimer, INVALID_HANDLE_VALUE); if (TimerQueue) DeleteTimerQueue(TimerQueue); TimerQueue = CreateTimerQueue(); CreateTimerQueueTimer(&RepaintTimer, TimerQueue, (WAITORTIMERCALLBACK)TimerCallback, this, 10, 15, WT_EXECUTEDEFAULT); return 0; }
int _tmain(int argc, _TCHAR **argv) { HANDLE hTimerQueue = CreateTimerQueue(); HANDLE hTimer = NULL; DWORD dwDueTimeInMs = 5000; DWORD dwPeriod = 1000; if (NULL == hTimerQueue) { _tperror(_T("Failed to create timer queue.")); return GetLastError(); } if (!CreateTimerQueueTimer(&hTimer, hTimerQueue, TimerRoutine, (PVOID)GetTickCount(), dwDueTimeInMs, dwPeriod, WT_EXECUTEDEFAULT)) { _tperror(_T("Failed to create timer.")); return GetLastError(); } _tprintf(_T("Call timer routine in %lu seconds...\n"), (unsigned long)dwDueTimeInMs / 1000); _tprintf(_T("Hit any key to delete the timer queue and cancel all queued timers!\n")); while (!_kbhit()) { } _getch(); if (!DeleteTimerQueueEx(hTimerQueue, INVALID_HANDLE_VALUE)) { _tprintf(_T("Failed to delete timer queue.\n")); return GetLastError(); } _tprintf(_T("Now I think it is time to say goodbye.\n")); return 0; }
GraphicsInterface::GraphicsInterface() { InitializeCriticalSection(&_csCreateDisplay); _hTimerQueue = CreateTimerQueue(); _hDisplayTimer = NULL; _nDisplayType = 0; _override_always_up = false; _bmInfo = NULL; if (m_ssSettings.bOSDAllMonitors) { CMonitors cm; for (int i = 0; i < cm.GetCount(); ++i) { _ges.push_back(new GraphicsEngine(i)); } } else { GraphicsEngine* ge = new GraphicsEngine(m_ssSettings.nOSDMonitor); _ges.push_back(ge); } }
DWORD StartHttpListener( PHTTP_LISTENER _listener, IN int urlCount, IN _TCHAR* urls[] ) { int UrlAdded = 0; DWORD result; ZeroMemory(&_listener->UrlGroupId, sizeof(HTTP_URL_GROUP_ID)); result = HttpCreateUrlGroup( _listener->SessionId, &_listener->UrlGroupId, NULL); if(result) { DEBUG_ASSERT(false); return result; } HTTP_BINDING_INFO httpBinding; ZeroMemory(&httpBinding, sizeof(httpBinding)); httpBinding.RequestQueueHandle = _listener->hRequestQueue; httpBinding.Flags.Present = true; result = HttpSetUrlGroupProperty( _listener->UrlGroupId, HttpServerBindingProperty, &httpBinding, sizeof(httpBinding)); // Add the urls to the UrlGroup for (int i = 1; i < urlCount; i++) { wprintf(L"we are listening for requests on the following url: %s\n", urls[i]); result = HttpAddUrlToUrlGroup( _listener->UrlGroupId, urls[i], NULL, NULL); if (result != NO_ERROR) { _listener->errorCode = result; wprintf(L"HttpAddUrl failed for %s with %lu \n\t", urls[i], result); return result; } else { UrlAdded ++; } } _listener->urls = urls; _listener->urlsCount = UrlAdded; // We will always have 10 oustanding requests. for(int j = 0 ;j < HTTP_LISTENER_MAX_PENDING_RECEIVES; j++) { result = EnsurePump(_listener); if(result != NO_ERROR) { break; } } _listener->TimerQueue = CreateTimerQueue(); _listener->LookAsideFlushPeriod = 5 *1000; if(_listener->TimerQueue != INVALID_HANDLE_VALUE) { if(CreateTimerQueueTimer(&_listener->FlushTimer, _listener->TimerQueue, HttpListenerFlushLookasideThreadProc, _listener, _listener->LookAsideFlushPeriod, _listener->LookAsideFlushPeriod, NULL) != FALSE) { result = NO_ERROR; } else { result = GetLastError(); } } else { result = GetLastError(); } if(result == NO_ERROR) { _listener->State = HTTP_LISTENER_STATE_STARTED; } return result; }
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { result = server.init(); packet_c.init(&server); if (result == 0) { HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); gTimerStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); gTimerDoneEvent = CreateEvent(NULL, TRUE, FALSE, NULL); hTimerQueue = CreateTimerQueue(); result = CoInitialize(NULL); if (result == 0) { result = app.init(); if (result == 0) { CreateTimerQueueTimer(&hTimer, hTimerQueue, (WAITORTIMERCALLBACK)Update, NULL, 60, DPF, 0); MSG winmsg; while (result == 0) { result = server.receive(); WaitForSingleObject(gTimerDoneEvent, DPF); if (GetMessage(&winmsg, NULL, 0, 0)) { TranslateMessage(&winmsg); DispatchMessage(&winmsg); } } SetEvent(gTimerStopEvent); WaitForSingleObject(gTimerDoneEvent, 1000); if (result > 1) { string error = "Runtime error:\n"; switch (result) { case 2: error.append("You have been disconnected."); break; } MessageBox(NULL, error.c_str(), NULL, MB_OK); } } else { MessageBox(NULL, (LPCSTR)"Failed to initialize windows app.", NULL, MB_OK); } CoUninitialize(); } server.close(); } else { string error = "Connection failure:\n"; switch (result) { case 1: error.append("Could not connect to server."); break; case 2: error.append("Incorrect handshake packet."); break; } MessageBox(NULL, error.c_str(), NULL, MB_OK); } return 0; }