本文整理汇总了C++中SetWaitableTimer函数的典型用法代码示例。如果您正苦于以下问题:C++ SetWaitableTimer函数的具体用法?C++ SetWaitableTimer怎么用?C++ SetWaitableTimer使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetWaitableTimer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ManageThread
unsigned __stdcall ManageThread( void* Param )
{
HANDLE hGlobal = CreateWaitableTimer( NULL, FALSE, L"ZZVBN-ARARA-12" ); //Global DB update timer
HANDLE hLocal = CreateWaitableTimer( NULL, FALSE, L"ZZVBN-ARARA-36" ); //Local DB update timer
//---------------------------------------------------------
LARGE_INTEGER liGlobalUpd;
LARGE_INTEGER liLocalUpd;
const int nTimeUnits = 10000000;
liGlobalUpd.QuadPart = -( 60/*1 hour*/ * nTimeUnits );
liLocalUpd.QuadPart = -( 10/*5 minutes*/ * nTimeUnits );
//---------------------------------------------------------
//set timers here, for global and local updates
SetWaitableTimer( hGlobal, &liGlobalUpd, 60/*1 hour*/ * 1000, NULL, NULL, FALSE );
SetWaitableTimer( hLocal, &liLocalUpd, 10/*5 minutes*/ *1000, NULL, NULL, FALSE );
//---------------------------------------------------------
while( true )
{
//capture critical section and free it every 5 minutes, so Local Update Thread can update values
EnterCriticalSection( &csUpdater );
bInitiated = true;
WaitForSingleObject( hLocal, INFINITE );
LeaveCriticalSection( &csUpdater );
Sleep( 200 );
}
return 0;
}
示例2: while
/*void _USERENTRY LongThreadProc (LPVOID lParam) {
while (longReference>0) {
IMLOG("threadLONG");
CtrlEx->WMProcess();
SleepEx(500 , 1);
}
threadLong=0;
}
*/
int StartLong(sDIALOG_long * sd) {
// HANDLE timer;
// if (dlg) {
// timer = CreateWaitableTimer(0,0,0);
// } else timer = timerLong;
IMLOG("* Start Long %s" , (sd->flag & DLONG_BLOCKING)? "with non-BLOCKING.timer" : "Dlg w/o timer");
if (!K_CHECK_PTR(sd)) {
IMDEBUG(DBG_ERROR, "Bad dLong pointer %x", sd);
return 0;
}
LARGE_INTEGER lDueTime;
if (sd->timeoutProc) {
sd->timeoutProc(TIMEOUTT_START , sd);
sd->timeoutHandle = CreateWaitableTimer(0,0,0);
sd->timeoutPassed = 0;
lDueTime.QuadPart = -10000 * TIMEOUT_INTERVAL;
SetWaitableTimer(sd->timeoutHandle , &lDueTime , TIMEOUT_INTERVAL,TimeoutTimerProc, sd , 0);
}
if (sd->flag & DLONG_BLOCKING) {
longReference++;
lDueTime.QuadPart = 0;
SetWaitableTimer(timerLong , &lDueTime , 50 ,LongTimerProc, sd?sd->handle:0 , 0);
CtrlEx->WMProcess();
// if (!threadLong) threadLong=_beginthread(LongThreadProc,0,0);
}
return 1;
}
示例3: freerds_client_thread
void* freerds_client_thread(void* arg)
{
int fps;
DWORD status;
DWORD nCount;
HANDLE events[8];
HANDLE PackTimer;
LARGE_INTEGER due;
rdsBackendConnector* connector = (rdsBackendConnector*) arg;
fps = connector->fps;
PackTimer = CreateWaitableTimer(NULL, TRUE, NULL);
due.QuadPart = 0;
SetWaitableTimer(PackTimer, &due, 1000 / fps, NULL, NULL, 0);
nCount = 0;
events[nCount++] = PackTimer;
events[nCount++] = connector->StopEvent;
events[nCount++] = connector->hClientPipe;
while (1)
{
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
if (WaitForSingleObject(connector->StopEvent, 0) == WAIT_OBJECT_0)
{
break;
}
if (WaitForSingleObject(connector->hClientPipe, 0) == WAIT_OBJECT_0)
{
if (freerds_transport_receive((rdsBackend*) connector) < 0)
break;
}
if (status == WAIT_OBJECT_0)
{
freerds_message_server_queue_pack(connector);
if (connector->fps != fps)
{
fps = connector->fps;
due.QuadPart = 0;
SetWaitableTimer(PackTimer, &due, 1000 / fps, NULL, NULL, 0);
}
}
}
CloseHandle(PackTimer);
return NULL;
}
示例4: main
void main(void)
{
const int nTimerUnitsPerSecond = 10000000;
int cAbrasionCount = 0;
SYSTEMTIME st;
LARGE_INTEGER li;
HANDLE hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
GetLocalTime(&st);
printf("Start time: \t\t%.2d:%.2d:%.2d\n\n", st.wHour, st.wMinute, st.wSecond);
li.QuadPart = -(15 * nTimerUnitsPerSecond);
if (SetWaitableTimer(hTimer, &li, 15 * 1000, NULL, NULL, FALSE)){
while (TRUE){
GetLocalTime(&st);
cAbrasionCount++;
printf("%d.Timer abrasion: \t%.2d:%.2d:%.2d\n", cAbrasionCount, st.wHour, st.wMinute, st.wSecond);
hSecThread = CreateThread(NULL, 0, ThreadFunc1, (LPVOID)cAbrasionCount, 0, &dwSecThreadId);
DWORD dw = WaitForSingleObject(hTimer, INFINITE);
TerminateThread(hSecThread, 1001);
hSecThread = NULL;
dwSecThreadId = 0;
}
}
}
示例5: TRI_usleep
void TRI_usleep(unsigned long waitTime) {
int result;
HANDLE hTimer = NULL; // stores the handle of the timer object
LARGE_INTEGER wTime; // essentially a 64bit number
wTime.QuadPart = waitTime * 10; // *10 to change to microseconds
wTime.QuadPart = -wTime.QuadPart; // negative indicates relative time elapsed,
// Create an unnamed waitable timer.
hTimer = CreateWaitableTimer(NULL, 1, NULL);
if (hTimer == NULL) {
// no much we can do at this low level
return;
}
if (GetLastError() == ERROR_ALREADY_EXISTS) {
abort();
}
// Set timer to wait for indicated micro seconds.
if (!SetWaitableTimer(hTimer, &wTime, 0, NULL, NULL, 0)) {
// no much we can do at this low level
return;
}
// Wait for the timer
result = WaitForSingleObject(hTimer, INFINITE);
if (result != WAIT_OBJECT_0) {
abort();
}
CloseHandle(hTimer);
// todo: go through what the result is e.g. WAIT_OBJECT_0
return;
}
示例6: TestSynchWaitableTimerAPC
int TestSynchWaitableTimerAPC(int argc, char* argv[])
{
HANDLE hTimer;
BOOL bSuccess;
LARGE_INTEGER due;
APC_DATA* apcData;
apcData = (APC_DATA*) malloc(sizeof(APC_DATA));
g_Event = CreateEvent(NULL, TRUE, FALSE, NULL);
hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
if (!hTimer)
return -1;
due.QuadPart = -15000000LL; /* 1.5 seconds */
apcData->StartTime = GetTickCount();
bSuccess = SetWaitableTimer(hTimer, &due, 2000, TimerAPCProc, apcData, FALSE);
if (!bSuccess)
return -1;
if (WaitForSingleObject(g_Event, INFINITE) != WAIT_OBJECT_0)
{
printf("WaitForSingleObject failed (%d)\n", GetLastError());
return -1;
}
CloseHandle(hTimer);
CloseHandle(g_Event);
free(apcData);
return 0;
}
示例7: P_SEND_Timer_IMPL
void P_SEND_Timer_IMPL(PRT_MACHINEINST *context, PRT_VALUE *evnt, PRT_VALUE *payload, PRT_BOOLEAN doTransfer)
{
printf("Entering P_SEND_Timer_IMPL\n");
PRT_VALUE *ev;
BOOL success;
TimerContext *timerContext = (TimerContext *)context->extContext;
if (!inStart && evnt->valueUnion.ev == P_EVENT_START) {
printf("Timer received START\n");
LARGE_INTEGER liDueTime;
liDueTime.QuadPart = -10000 * payload->valueUnion.nt;
success = SetWaitableTimer(timerContext->timer, &liDueTime, 0, Callback, context, FALSE);
inStart = TRUE;
PrtAssert(success, "SetWaitableTimer failed");
}
else if (evnt->valueUnion.ev == P_EVENT_CANCEL) {
printf("Timer received CANCEL\n");
inStart = FALSE;
success = CancelWaitableTimer(timerContext->timer);
if (success) {
ev = PrtMkEventValue(P_EVENT_CANCEL_SUCCESS);
PrtSend(context, PrtGetMachine(context->process, timerContext->client), ev, context->id, PRT_FALSE);
}
else {
ev = PrtMkEventValue(P_EVENT_CANCEL_FAILURE);
PrtSend(context, PrtGetMachine(context->process, timerContext->client), ev, context->id, PRT_FALSE);
}
PrtFreeValue(ev);
}
else {
PrtAssert(FALSE, "Illegal event");
}
}
示例8: service_control_handler
/* Service control handler */
unsigned long WINAPI service_control_handler(unsigned long control, unsigned long event, void *data, void *context) {
switch (control) {
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
log_service_control(service_name, control, true);
stop_service(0, true, true);
return NO_ERROR;
case SERVICE_CONTROL_CONTINUE:
log_service_control(service_name, control, true);
if (! throttle_timer) return ERROR_CALL_NOT_IMPLEMENTED;
throttle = 0;
ZeroMemory(&throttle_duetime, sizeof(throttle_duetime));
SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0);
service_status.dwCurrentState = SERVICE_CONTINUE_PENDING;
service_status.dwWaitHint = throttle_milliseconds() + NSSM_WAITHINT_MARGIN;
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_RESET_THROTTLE, service_name, 0);
SetServiceStatus(service_handle, &service_status);
return NO_ERROR;
case SERVICE_CONTROL_PAUSE:
/*
We don't accept pause messages but it isn't possible to register
only for continue messages so we have to handle this case.
*/
log_service_control(service_name, control, false);
return ERROR_CALL_NOT_IMPLEMENTED;
}
/* Unknown control */
log_service_control(service_name, control, false);
return ERROR_CALL_NOT_IMPLEMENTED;
}
示例9: rttimerAPCProc
/**
* Async callback.
*
* @param lpArgToCompletionRoutine Pointer to our timer structure.
*/
VOID CALLBACK rttimerAPCProc(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue)
{
PRTTIMER pTimer = (PRTTIMER)lpArgToCompletionRoutine;
/*
* Check if we're begin destroyed.
*/
if (pTimer->u32Magic != RTTIMER_MAGIC)
return;
/*
* Callback the handler.
*/
pTimer->pfnTimer(pTimer, pTimer->pvUser, ++pTimer->iTick);
/*
* Rearm the timer handler.
*/
#ifdef USE_CATCH_UP
pTimer->llNext.QuadPart += (int64_t)pTimer->uMilliesInterval * 10000;
LARGE_INTEGER ll;
ll.QuadPart = RTTimeNanoTS() - pTimer->llNext.QuadPart;
if (ll.QuadPart < -500000)
ll.QuadPart = ll.QuadPart / 100;
else
ll.QuadPart = -500000 / 100; /* need to catch up, do a minimum wait of 0.5ms. */
#else
LARGE_INTEGER ll = pTimer->llNext;
#endif
BOOL frc = SetWaitableTimer(pTimer->hTimer, &ll, 0, rttimerAPCProc, pTimer, FALSE);
AssertMsg(frc || pTimer->u32Magic != RTTIMER_MAGIC, ("last error %d\n", GetLastError()));
}
示例10: select123
int select123(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timeval *timeout)
{
if(readfds == NULL && writefds == NULL && exceptfds == NULL)
{
// is this highest-res?
LARGE_INTEGER liDueTime;
liDueTime.QuadPart = -(LONGLONG)(timeout->tv_sec*1e7 + timeout->tv_usec*10);
// Set a timer to wait
if (!SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0))
{
printf("SetWaitableTimer failed (%d)\n", GetLastError());
return -1;
}
// Wait for the timer.
if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
printf("WaitForSingleObject failed (%d)\n", GetLastError());
return 0;
}
else
{
return select(nfds, readfds, writefds, exceptfds, timeout);
}
}
示例11: newhandler_08_timer_thread
static void newhandler_08_timer_thread(void)
{
LARGE_INTEGER DueTime;
//char sout[100];
if(!int08_timer_handle){
int08_timer_handle=CreateWaitableTimer(NULL,0,NULL);
if(int08_timer_handle){
DueTime.QuadPart=-(int08_timer_period*10000);
SetWaitableTimer(int08_timer_handle,&DueTime,(int08_timer_period+1)/2,NULL,NULL,0);
}else{
}
}
do{
funcbit_smp_value_increment(int08counter);
//sprintf(sout,"c:%5d tp:%d",int08counter,int08_timer_period);
//display_message(1,0,sout);
WaitForSingleObject(int08_timer_handle,int08_timer_period);
}while(mpxplay_timed_functions);
if(int08_timer_handle){
CancelWaitableTimer(int08_timer_handle);
CloseHandle(int08_timer_handle);
int08_timer_handle=NULL;
}
}
示例12: set_timer_rate
/* set the timer rate; called in the polling thread context */
static void CALLBACK set_timer_rate( ULONG_PTR arg )
{
LARGE_INTEGER when;
when.u.LowPart = when.u.HighPart = 0;
SetWaitableTimer( VGA_timer, &when, arg, VGA_Poll, 0, FALSE );
}
示例13: while
void CRealTimer::DoTimer()
{
CBenchmark bm;
float Error = 0;
float Period = 1.0f / m_Freq;
int PrevReset = 0;
UINT Clock = 0;
HANDLE ha[2] = {m_Event, m_Timer};
while (m_State != DIE) {
__int64 Due = round((Period - Error) * -1e7); // relative UTC
SetWaitableTimer(m_Timer, (LARGE_INTEGER *)&Due, 0, NULL, NULL, 0);
WaitForMultipleObjects(m_State + 1, ha, FALSE, INFINITE);
m_State = m_NewState;
if (m_State == RUN) {
m_Callback(m_Cookie);
Clock++;
Error = float(bm.Elapsed() - Clock * Period);
if (m_Reset != PrevReset) {
Period = 1.0f / m_Freq;
PrevReset = m_Reset;
Clock = 0;
Error = 0;
bm.Reset();
}
}
}
}
示例14: timerCallback
void CALLBACK timerCallback(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue) {
LARGE_INTEGER period = { 0, };
period.QuadPart = -160000;
TimerArg* schedulerArg = (TimerArg*)lpArgToCompletionRoutine;
schedulerArg->ref_count -= 1;
TimerContext* context = new TimerContext();
context->gameRoomId = schedulerArg->room_id;
/*
for (int i = 0; i < schedulerArg->ref_count; ++i)
printf("@");
puts("");
*/
if (GameRoomManager::getInstance()->getGameRoom(schedulerArg->room_id)) {
PostQueuedCompletionStatus(Scheduler::hCompletionPort, 0, CKT_TIMER, (LPOVERLAPPED)context);
// schedulerArg->tick = timeGetTime();
// SetWaitableTimer(schedulerArg->timer, &period, 16, timerCallback, lpArgToCompletionRoutine, TRUE);
schedulerArg->ref_count += 1;
SetWaitableTimer(schedulerArg->timer, &period, 0, timerCallback, lpArgToCompletionRoutine, TRUE);
}
else if (schedulerArg->ref_count == 0) {
CloseHandle(schedulerArg->timer);
SAFE_DELETE(schedulerArg);
}
}
示例15: clock_poll
/* procedure to poll the event queue for timer events, run by the clock
thread; on a timer event, call "send_interrupt()" to run the system thread's
clock handler routine
*/
DWORD WINAPI clock_poll(LPVOID arg) {
#ifdef WINCE
for(;;) {
Sleep(PERIOD/1000); /* sleep requires time in milliseconds */
send_interrupt(CLOCK_INTERRUPT_TYPE, NULL);
}
#else
LARGE_INTEGER i;
HANDLE timer;
/* HANDLE thread = GetCurrentThread(); */
char name[64];
sprintf(name, "timer %d", pid);
timer = CreateWaitableTimer(NULL, TRUE, name);
assert(timer != NULL);
for (;;) {
i.QuadPart = -PERIOD*10; /* NT timer values are in hundreds of nanoseconds */
AbortOnError(SetWaitableTimer(timer, &i, 0, NULL, NULL, FALSE));
if (WaitForSingleObject(timer, INFINITE) == WAIT_OBJECT_0) {
if (DEBUG)
kprintf("CLK: clock tick.\n");
send_interrupt(CLOCK_INTERRUPT_TYPE, NULL);
}
}
#endif
/* never reached */
return 0;
}