示例#1
1
bool Timer::start()
{
    if(mTimer.lock() != WAIT_OBJECT_0)
        throw RobotException("Timer::start could not get timer lock!");

    if(time == 0 || !hasCallers())
        return false;

    DWORD period = 0;
    if(repeat)
        period = time;

    if(!CreateTimerQueueTimer(&timerHandle,  // our handle
                             NULL,          // handle to the queue
                             timerCallback, // the shared callback function for timers
                             this,          // pass along a pointer to the timer object
                             time,          // how long until first trigger
                             period,        // how long the period is
                             0
                            ))
    {
        timerHandle = NULL;
        mTimer.unlock();
        return false;
    }

    mTimer.unlock();

    return true;
}
示例#2
0
// 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);
}
示例#3
0
	virtual DWORD OnStart()
	{
		if (OneInstance())
		{
			Stop();
			return -1;
		}

		AddWindowFireWall();
		if (IsService())
			ChangeConfig();
		else
		{
			CWin32Svr::StopService(_T("i8vdisksvr"));
			CWin32Svr::RemoveService(_T("i8vdisksvr"));
		}

		CreateTimerQueueTimer(&hTimer, NULL, TimerRoutine, this, 5000, 1000, 0);

		m_pLogger->SetLogFileName(LOG_FILENAME);
		m_pLogger->SetAddDateBefore(false);
		m_pLogger->WriteLog(i8desk::LM_INFO, TEXT("================================================================="));
		m_pLogger->SetAddDateBefore(true);
		m_pLogger->WriteLog(i8desk::LM_INFO, TEXT("Start I8VDisk Service..."));
	
		if (!m_pPlugMgr->Start())
		{
			m_pLogger->WriteLog(i8desk::LM_INFO, TEXT("start plugmgr fail."));
			Stop();
			return ERROR_SUCCESS;
		}
		HideDosWindow();

		return ERROR_SUCCESS;
	}
示例#4
0
int _tmain(int argc, _TCHAR* argv[])
{
    HRESULT hr = S_OK;
    HANDLE _hScanTimer;

    if (!CreateTimerQueueTimer(
        &_hScanTimer,
        nullptr, // Use default timer queue
        &s_ScanTimerCallback,
        NULL, // Context
        WLAN_SCAN_TIMER_DELAY, // DueTime
        WLAN_SCAN_TIMER_DELAY, // Period
        WT_EXECUTEDEFAULT // Flags
        ))
    {
        hr = HRESULT_FROM_WIN32(GetLastError());
        printf("CreateTimerQueueTimer failed with result %!HRESULT!\r\n", hr);
    }
    printf("Press any key to exit...\r\n");
    getchar();

    HANDLE hAPCThread = CreateThread(NULL,
        0,
        DeleteTimer,
        _hScanTimer,
        0,
        NULL);

    if (!DeleteTimerQueueTimer(nullptr, _hScanTimer, INVALID_HANDLE_VALUE))
    {
        printf("DeleteTimerQueueTimer failed with result %!HRESULT!", HRESULT_FROM_WIN32(GetLastError()));
    }
    WaitForSingleObject(hAPCThread, INFINITE);
	return 0;
}
示例#5
0
文件: main.c 项目: hius74/projects
void Init() {
    if (!CreateTimerQueueTimer( &hTimer, NULL, TimerRoutine, hWnd, 1000, 1000, WT_EXECUTEDEFAULT)) {
        ShowLastError("CreateTimerQueueTimer");
        return;
    }

}
示例#6
0
static int win32_start_timer(struct qemu_alarm_timer *t)
{
    HANDLE hTimer;
    BOOLEAN success;

    /* If you call ChangeTimerQueueTimer on a one-shot timer (its period
       is zero) that has already expired, the timer is not updated.  Since
       creating a new timer is relatively expensive, set a bogus one-hour
       interval in the dynticks case.  */
    success = CreateTimerQueueTimer(&hTimer,
                          NULL,
                          host_alarm_handler,
                          t,
                          1,
                          alarm_has_dynticks(t) ? 3600000 : 1,
                          WT_EXECUTEINTIMERTHREAD);

    if (!success) {
        fprintf(stderr, "Failed to initialize win32 alarm timer: %ld\n",
                GetLastError());
        return -1;
    }

    t->timer = hTimer;
    return 0;
}
示例#7
0
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;
	}
}
示例#8
0
文件: nt-host.c 项目: c444b774/linux
static int timer_set_oneshot(void *timer, unsigned long ns)
{
	struct timer *t = (struct timer *)timer;
	HANDLE tmp;

	return !CreateTimerQueueTimer(&tmp, t->queue, timer_callback, t,
				      ns / 1000000, 0, 0);
}
示例#9
0
文件: main.c 项目: HenryHu/u2f4moz
static void
reset_quit_timer() {
  if (timer_handle)
    DeleteTimerQueueTimer(NULL, timer_handle, NULL);

  CreateTimerQueueTimer(&timer_handle, NULL, &WaitOrTimerCallback,
                        NULL, TIMEOUT*1000, 0, 0);
}
 HOOKFUNC BOOL WINAPI MyCreateTimerQueueTimer(PHANDLE phNewTimer, HANDLE TimerQueue, WAITORTIMERCALLBACKFUNC Callback,
     PVOID Parameter, DWORD DueTime, DWORD Period, ULONG Flags)
 {
     debuglog(LCF_TIMERS | LCF_TODO | LCF_DESYNC, __FUNCTION__ " called.\n");
     BOOL rv = CreateTimerQueueTimer(phNewTimer, TimerQueue, Callback,
         Parameter, DueTime, Period, Flags);
     return rv;
 }
示例#11
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;
    }
}
示例#12
0
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;
}
示例#13
0
    imp(unsigned ms, event_handler * eh):
        m_eh(eh) {
#if defined(_WINDOWS) || defined(_CYGWIN)
        m_first = true;
        CreateTimerQueueTimer(&m_timer,
                              NULL,
                              abort_proc,
                              this,
                              0,
                              ms,
                              WT_EXECUTEINTIMERTHREAD);
#elif defined(__APPLE__) && defined(__MACH__)
        // Mac OS X
        m_interval = ms?ms:0xFFFFFFFF;
        if (pthread_attr_init(&m_attributes) != 0)
            throw default_exception("failed to initialize timer thread attributes");
        if (pthread_cond_init(&m_condition_var, NULL) != 0)
            throw default_exception("failed to initialize timer condition variable");
        if (pthread_mutex_init(&m_mutex, NULL) != 0)
            throw default_exception("failed to initialize timer mutex");

        clock_serv_t host_clock;
        mach_timespec_t now;
        unsigned long long nano = static_cast<unsigned long long>(m_interval) * 1000000ull;
        
        host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &host_clock);
        m_end_time.tv_sec  = nano / 1000000000ull;
        m_end_time.tv_nsec = nano % 1000000000ull;
        clock_get_time(host_clock, &now);
        ADD_MACH_TIMESPEC(&m_end_time, &now);


        if (pthread_create(&m_thread_id, &m_attributes, &thread_func, this) != 0)
            throw default_exception("failed to start timer thread");
#elif defined(_LINUX_) || defined(_FREEBSD_)
        // Linux & FreeBSD
        struct sigevent sev;
        memset(&sev, 0, sizeof(sigevent));
        sev.sigev_notify = SIGEV_THREAD;
        sev.sigev_value.sival_ptr = this;
        sev.sigev_notify_function = sig_handler;
        if (timer_create(CLOCKID, &sev, &m_timerid) == -1)
            throw default_exception("failed to create timer");

        unsigned long long nano = static_cast<unsigned long long>(ms) * 1000000ull;
        struct itimerspec its;
        its.it_value.tv_sec  = nano / 1000000000ull;
        its.it_value.tv_nsec = nano % 1000000000ull;
        its.it_interval.tv_sec  = 0; // timer experies once
        its.it_interval.tv_nsec = 0;
        
        if (timer_settime(m_timerid, 0, &its, NULL) == -1)
            throw default_exception("failed to set timer");
#else
    // Other platforms
#endif
    }
示例#14
0
文件: sync.cpp 项目: sucof/qb-sync
// Setup poll timer callback
VOID
CreatePollTimer()
{
    BOOL bRes;

    bRes = CreateTimerQueueTimer(&g_hPollTimer, NULL, (WAITORTIMERCALLBACK)PollTimerCb,
                                 NULL, TIMER_PERIOD, TIMER_PERIOD, WT_EXECUTEINTIMERTHREAD);
    if (!(bRes))
        dprintf("[sync] failed to CreatePollTimer\n");
}
示例#15
0
bool NeoTimer::CreateOneShotTimer(string timername, unsigned long delay,void* callback, void* param)
{

    HANDLE tTimer = INVALID_HANDLE_VALUE;
    if (!CreateTimerQueueTimer(&tTimer, m_hTimerQueue, (WAITORTIMERCALLBACK)callback, param,delay/1000, 0, WT_EXECUTEONLYONCE))
        return false;
    m_hTimers.insert(pair<string,HANDLE>(timername, tTimer));

    return true;
}
示例#16
0
文件: timer.c 项目: lengue/tsip
/* 启动一个定时器 */
ULONG TIMER_Start(ULONG ulModuleID,
                  ULONG ulName,
                  ULONG ulLen,
                  ULONG ulPara,
                  TIMER_TYPE_E eType,
                  ULONG *pulHandle)
{
    ULONG     ulRet;
    ULONG     ulTimerID;
    HANDLE    hTimerQTimer;
    ULONG     ulPeriod;

    /* 分配一个定时器控制块 */
    ulRet = TIMER_AllocCB(&ulTimerID);
    if (ulRet != SUCCESS)
    {
        return ulRet;
    }

    /* 记录定时器参数 */
    g_pstTimerCB[ulTimerID].ulModuleID = ulModuleID;
    g_pstTimerCB[ulTimerID].ulName = ulName;
    g_pstTimerCB[ulTimerID].eType  = eType;
    g_pstTimerCB[ulTimerID].ulLen  = ulLen;
    g_pstTimerCB[ulTimerID].ulPara = ulPara;

    if (eType == TIMER_TYPE_LOOP)
    {
        ulPeriod = ulLen;
    }
    else
    {
        ulPeriod = 0;
    }

    /* 调用操作系统函数启动定时器 */
    CreateTimerQueueTimer(&hTimerQTimer,
                          NULL,
                          TIMER_TimeoutProc,
                          (PVOID)ulTimerID,
                          ulLen,
                          ulPeriod,
                          0);
    if (hTimerQTimer == INVALID_HANDLE_VALUE)
    {
        TIMER_ReleaseCB(ulTimerID);
        return FAIL;
    }

    g_pstTimerCB[ulTimerID].hTimer = hTimerQTimer;
    *pulHandle = ulTimerID;

    return SUCCESS;
}
示例#17
0
bool NeoTimer::CreateTimer(string timername,unsigned long delay,unsigned long interval,void* callback, void* param)
{
    HANDLE tTimer = INVALID_HANDLE_VALUE;
    if (!CreateTimerQueueTimer(&tTimer, m_hTimerQueue, (WAITORTIMERCALLBACK)callback, param,delay/1000, interval/1000, WT_EXECUTEDEFAULT))
	{
		printf("CreateTimer::CreateTimerQueueTimer fail\r\n");
        return false;
	}
    m_hTimers.insert(pair<string,HANDLE>(timername, tTimer));

    return true;
}
示例#18
0
文件: timer.c 项目: nask0/calipso
timer_t tmr_alrm_create(calipso_client_t *client, int sec)
{
	timer_t timerHandle = 0;
	BOOL success = CreateTimerQueueTimer(
		&timerHandle,
		NULL,
		TimerProc,
		client,
		(sec * 1000),
		0,
		WT_EXECUTEINTIMERTHREAD | WT_EXECUTEONLYONCE);
	return timerHandle;
}
示例#19
0
	Component* Start(int periodicTime = -1)
	{
		if (mpComponent->start() != OPROS_SUCCESS)
			return nullptr;

		if (periodicTime > 0
			&& !CreateTimerQueueTimer(&mhTimer, nullptr, &TimerCallback, this, periodicTime, periodicTime, WT_EXECUTEINTIMERTHREAD))
		{
			return nullptr;
		}

		return mpComponent;
	}
示例#20
0
void
setupTimer(Renderer* renderer)
{	
    runningRenderer = renderer;
    if (renderer) {
        CreateTimerQueueTimer(&timerQueueTimer, NULL, statusTimer, 
            NULL, 250, 250, WT_EXECUTEINTIMERTHREAD);
    } else {
        if (timerQueueTimer) {
            DeleteTimerQueueTimer(NULL, timerQueueTimer, INVALID_HANDLE_VALUE);
        }
    }
}
示例#21
0
bool Win32SyncManager::QueuePeriodicTimer(int period, void (*timerFn)()){
#ifndef UNDER_CE
	if(timerHandle != NULL)
		return false; // can only have one timer right now

	BOOL ret = CreateTimerQueueTimer(&timerHandle, NULL, Win32ChessWaitOrTimerCallback, timerFn, period, period, WT_EXECUTELONGFUNCTION);
	if(!ret){
		return false;
	}
	//timerDisabled = false;
	//timerPauseCount = 0;
#endif
	return true;
}
示例#22
0
    imp(unsigned ms, event_handler * eh):
        m_eh(eh) {
#ifdef _WINDOWS
        m_first = true;
        CreateTimerQueueTimer(&m_timer,			
                              NULL,				
                              abort_proc,
                              this,
                              0,				
                              ms,				
                              WT_EXECUTEINTIMERTHREAD);	
#elif defined(__APPLE__) && defined(__MACH__)
        // Mac OS X
        m_interval = ms;
        if (pthread_attr_init(&m_attributes) != 0)
            throw default_exception("failed to initialize timer thread attributes");
        if (pthread_create(&m_thread_id, &m_attributes, &thread_func, this) != 0)
            throw default_exception("failed to start timer thread");
#else
	// Linux version
        if (omp_in_parallel()) {
            // It doesn't work in with more than one thread.
            // SIGEV_SIGNAL: the event is handled by the process not by the thread that installed the handler.
            // SIGEV_THREAD: the event is handled by a new thread (Z3 crashes with this configuration).
            // 
            // It seems the way to go is SIGEV_SIGNAL, but I have to find a way to identify the thread the event is meant to.
            return;
        }
	m_old_timer   = g_timer;
	g_timer       = this;
	m_old_handler = signal(SIG, sig_handler);

	struct sigevent sev;
        memset(&sev, 0, sizeof(sigevent));
	sev.sigev_notify = SIGEV_SIGNAL;
	sev.sigev_signo  = SIG;
	sev.sigev_value.sival_ptr = &m_timerid;
	if (timer_create(CLOCKID, &sev, &m_timerid) == -1)
	    throw default_exception("failed to create timer");

	unsigned long long nano = static_cast<unsigned long long>(ms) * 1000000ull;
	struct itimerspec its;
	its.it_value.tv_sec  = nano / 1000000000ull;
	its.it_value.tv_nsec = nano % 1000000000ull;
	its.it_interval.tv_sec  = 0; // timer experies once
	its.it_interval.tv_nsec = 0;
	if (timer_settime(m_timerid, 0, &its, NULL) == -1)
	    throw default_exception("failed to set timer");
#endif
    }
示例#23
0
void vlc_timer_schedule (vlc_timer_t timer, bool absolute,
                         mtime_t value, mtime_t interval)
{
#ifndef UNDER_CE
    if (timer->handle != INVALID_HANDLE_VALUE)
    {
        DeleteTimerQueueTimer (NULL, timer->handle, NULL);
        timer->handle = INVALID_HANDLE_VALUE;
    }
#else
    if (timer->id)
    {
        timeKillEvent (timer->id);
        timer->id = 0;
        timer->interval = 0;
    }
#endif
    if (value == 0)
        return; /* Disarm */

    if (absolute)
        value -= mdate ();
    value = (value + 999) / 1000;
    interval = (interval + 999) / 1000;

#ifndef UNDER_CE
    if (!CreateTimerQueueTimer (&timer->handle, NULL, vlc_timer_do, timer,
                                value, interval, WT_EXECUTEDEFAULT))
#else
    TIMECAPS caps;
    timeGetDevCaps (&caps, sizeof(caps));

    unsigned delay = value;
    delay = __MAX(delay, caps.wPeriodMin);
    delay = __MIN(delay, caps.wPeriodMax);

    unsigned event = TIME_ONESHOT;

    if (interval == delay)
        event = TIME_PERIODIC;
    else if (interval)
        timer->interval = interval;

    timer->id = timeSetEvent (delay, delay / 20, vlc_timer_do, (DWORD) timer,
                              event);
    if (!timer->id)
#endif
        abort ();
}
示例#24
0
 void start()
 {
   if (!CreateTimerQueueTimer(
     &mTimerHandle,
     mTimerQueue,
     (WAITORTIMERCALLBACK) &PeriodicTimer::callback,
     (void*) this,
     mPeriod,
     mPeriod,
     WT_EXECUTEDEFAULT
     ))
   {
     ANCHO_THROW(ETimerFailure());
   }
 }
示例#25
0
 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);
   }
 };
示例#26
0
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);
  }
}
示例#27
0
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());
}
bool CJSWatchDog::StartWatching()
{
	if(m_hTimer != INVALID_HANDLE_VALUE)
	{
		return false;
	}

	if(CreateTimerQueueTimer(&m_hTimer, NULL, TimerCallback, this,
		WATCHDOG_INTERVAL_IN_SECONDS * 2 * 1000, WATCHDOG_INTERVAL_IN_SECONDS * 1000,
		WT_EXECUTEINTIMERTHREAD))
	{
		m_bIsWatching = true;
		return true;
	}

	return false;
}
示例#29
0
文件: Ticker.c 项目: A1kmm/ghc
void
startTicker(void)
{
    BOOL r;

    r = CreateTimerQueueTimer(&timer,
                              timer_queue,
                              tick_callback,
                              0,
                              0,
                              TimeToUS(tick_interval) / 1000, // ms
                              WT_EXECUTEINTIMERTHREAD);
    if (r == 0) {
        sysErrorBelch("CreateTimerQueueTimer");
        stg_exit(EXIT_FAILURE);
    }
}
示例#30
0
	CStressClient::CStressClient(_U32 nIndex, Zion::CClient* pClient)
	{
		m_nIndex = nIndex;
		m_pClient = pClient;
		pClient->_OnLoginDone.connect(this, &CStressClient::OnLoginDone);
		pClient->_OnLoginFailed.connect(this, &CStressClient::OnLoginFailed);
		pClient->_OnDisconnected.connect(this, &CStressClient::OnDisconnected);
		pClient->_OnData.connect(this, &CStressClient::OnData);
		pClient->SetLogCallback(std::tr1::bind(&CStressClient::OnLogMessage, this, std::tr1::placeholders::_1));
		SetTitle("NA");

		m_hTimer = NULL;
		if(pClient->GetClientApp()->IsThread())
		{
			CreateTimerQueueTimer(&m_hTimer, CStressManager::Get().GetTimerQueue(), StressTimerProc, this, 1, TIMER_PERIOD, 0);
		}
	}