本文整理汇总了C++中CreateWaitableTimer函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateWaitableTimer函数的具体用法?C++ CreateWaitableTimer怎么用?C++ CreateWaitableTimer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateWaitableTimer函数的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: m_pLib
COverlayRenderer::COverlayRenderer(CLibBlurayWrapper* pLib) :
m_pLib(pLib),
m_pD3DDevice(NULL)
{
m_pPlanes[BD_OVERLAY_PG] = NULL;
m_pPlanes[BD_OVERLAY_IG] = NULL;
m_pPlanesBackbuffer[BD_OVERLAY_PG] = NULL;
m_pPlanesBackbuffer[BD_OVERLAY_IG] = NULL;
m_pARGBTextures[BD_OVERLAY_PG] = NULL;
m_pARGBTextures[BD_OVERLAY_IG] = NULL;
m_overlayType[BD_OVERLAY_PG] = NONE;
m_overlayType[BD_OVERLAY_IG] = NONE;
ZeroMemory((void*)&m_ARGBBuffer, sizeof(BD_ARGB_BUFFER_EX));
m_hStopThreadEvent = CreateEvent(0, TRUE, FALSE, 0);
m_hNewOverlayAvailable = CreateEvent(0, TRUE, FALSE, 0);
m_hThread = CreateThread(0, 0, COverlayRenderer::ScheduleThreadEntryPoint, (LPVOID)this, 0, NULL);
m_hOverlayTimerIG = CreateWaitableTimer(NULL, false, NULL);
m_hOverlayTimerPG = CreateWaitableTimer(NULL, false, NULL);
}
示例3: start_benchmark
void start_benchmark(struct benchmark_st * st)
{
memset(st, 0, sizeof(*st));
#ifndef _WIN32
st->old_handler = signal (SIGALRM, alarm_handler);
#endif
gettime (&st->start);
benchmark_must_finish = 0;
#if defined(_WIN32)
st->wtimer = CreateWaitableTimer (NULL, TRUE, NULL);
if (st->wtimer == NULL)
{
fprintf (stderr, "error: CreateWaitableTimer %u\n", GetLastError ());
exit(1);
}
st->wthread = CreateThread (NULL, 0, alarm_handler, &st->wtimer, 0, NULL);
if (st->wthread == NULL)
{
fprintf (stderr, "error: CreateThread %u\n", GetLastError ());
exit(1);
}
st->alarm_timeout.QuadPart = (BSECS) * 10000000;
if (SetWaitableTimer (st->wtimer, &st->alarm_timeout, 0, NULL, NULL, FALSE) == 0)
{
fprintf (stderr, "error: SetWaitableTimer %u\n", GetLastError ());
exit(1);
}
#else
alarm (BSECS);
#endif
}
示例4: 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;
}
示例5: 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;
}
示例6: asio_event_subscribe
void asio_event_subscribe(asio_event_t* ev)
{
if((ev == NULL) ||
(ev->flags == ASIO_DISPOSABLE) ||
(ev->flags == ASIO_DESTROYED))
return;
asio_backend_t* b = asio_get_backend();
if(ev->noisy)
asio_noisy_add();
if((ev->flags & ASIO_TIMER) != 0)
{
// Need to start a timer.
// We can create it here but not start it. That must be done in the
// background thread because that's where we want the fire APC to happen.
// ev->data is initially the time (in nsec) and ends up as the handle.
ev->timer = CreateWaitableTimer(NULL, FALSE, NULL);
send_request(ev, ASIO_SET_TIMER);
} else if((ev->flags & ASIO_SIGNAL) != 0) {
if(ev->nsec < MAX_SIGNAL)
send_request(ev, ASIO_SET_SIGNAL);
} else if(ev->fd == 0) {
// Need to subscribe to stdin
send_request(ev, ASIO_STDIN_NOTIFY);
}
}
示例7: Close
bool WTimer::Create(LPSECURITY_ATTRIBUTES lpTimerAttributes,
BOOL bManualReset, LPCTSTR lpTimerName)
{
Close();
m_Timer = CreateWaitableTimer(lpTimerAttributes, bManualReset, lpTimerName);
return(m_Timer != NULL);
}
示例8: usleep
void usleep(__int64 waitTime)
{
if (waitTime > 0)
{
if (waitTime > 100)
{
// use a waitable timer for larger intervals > 0.1ms
HANDLE timer;
LARGE_INTEGER ft;
ft.QuadPart = -(10*waitTime); // Convert to 100 nanosecond interval, negative value indicates relative time
timer = CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
}
else
{
// use a polling loop for short intervals <= 100ms
LARGE_INTEGER perfCnt, start, now;
__int64 elapsed;
QueryPerformanceFrequency(&perfCnt);
QueryPerformanceCounter(&start);
do {
QueryPerformanceCounter((LARGE_INTEGER*) &now);
elapsed = (__int64)((now.QuadPart - start.QuadPart) / (float)perfCnt.QuadPart * 1000 * 1000);
} while ( elapsed < waitTime );
}
}
}
示例9: ros_nanosleep
/**
* @brief Simple representation of the rt library nanosleep function.
*/
int ros_nanosleep(const uint32_t &sec, const uint32_t &nsec)
{
#if defined(WIN32)
HANDLE timer = NULL;
LARGE_INTEGER sleepTime;
sleepTime.QuadPart = -
static_cast<int64_t>(sec)*10000000LL -
static_cast<int64_t>(nsec) / 100LL;
timer = CreateWaitableTimer(NULL, TRUE, NULL);
if (timer == NULL)
{
return -1;
}
if (!SetWaitableTimer (timer, &sleepTime, 0, NULL, NULL, 0))
{
return -1;
}
if (WaitForSingleObject (timer, INFINITE) != WAIT_OBJECT_0)
{
return -1;
}
return 0;
#else
timespec req = { sec, nsec };
return nanosleep(&req, NULL);
#endif
}
示例10: ts3plugin_init
/*
* Custom code called right after loading the plugin. Returns 0 on success, 1 on failure.
* If the function returns 1 on failure, the plugin will be unloaded again.
*/
int ts3plugin_init() {
// Create the command mutex
hMutex = CreateMutex(NULL, FALSE, NULL);
// Create the PTT delay timer
hPttDelayTimer = CreateWaitableTimer(NULL, FALSE, NULL);
// Find and open the settings database
char db[MAX_PATH];
ts3Functions.getConfigPath(db, MAX_PATH);
_strcat(db, MAX_PATH, "settings.db");
ts3Settings.OpenDatabase(db);
// Find the error sound and info icon
SetErrorSound();
SetInfoIcon();
// Start the plugin threads
pluginRunning = true;
hMailslotThread = CreateThread(NULL, (SIZE_T)NULL, MailslotThread, 0, 0, NULL);
if(hMailslotThread==NULL)
{
ts3Functions.logMessage("Failed to start threads, unloading plugin", LogLevel_ERROR, "NiftyKb Plugin", 0);
return 1;
}
/* Initialize return codes array for requestClientMove */
memset(requestClientMoveReturnCodes, 0, REQUESTCLIENTMOVERETURNCODES_SLOTS * RETURNCODE_BUFSIZE);
return 0; /* 0 = success, 1 = failure */
}
示例11: main
int main(int argc, char *argv[])
{
HANDLE hThread;
DWORD IDThread;
LARGE_INTEGER due;
ZeroMemory(&due, sizeof(LARGE_INTEGER));
due.QuadPart = -20000000; // 2 - секунды перед стартом таймера
hTimer = CreateWaitableTimer(NULL, FALSE, L"MyTimer");
if (hTimer == NULL) {
cout << "error CreateWaitableTimer" << endl;
return GetLastError();
}
if (!SetWaitableTimer(hTimer, &due, 1000, NULL, NULL, 0)) { // дальше повтор с интервалов 1 -сек
cout << "error SetWaitableTimer" << endl;
return GetLastError();
}
hThread = CreateThread(NULL, 0, Thread, NULL, 0, &IDThread);
if (hThread == NULL)
return GetLastError();
while (!GetAsyncKeyState(VK_ESCAPE)); // чтобы не завершилась приложение пускай ждёт ESC
aborts = FALSE; // пускаем сброс цикла в поток для завершения
CloseHandle(hThread);
CancelWaitableTimer(hTimer);
CloseHandle(hTimer);
return 0;
}
示例12: timer_start
HANDLE timer_start(int usec)
{
timeBeginPeriod(1);
hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
if(hTimer)
{
LARGE_INTEGER li = { .QuadPart = -(usec*10) };
if(!SetWaitableTimer(hTimer, &li, usec / 1000, NULL, NULL, FALSE))
{
fprintf(stderr, "SetWaitableTimer failed.\n");
hTimer = NULL;
}
}
else
{
fprintf(stderr, "CreateWaitableTimer failed.\n");
}
if(!hTimer)
{
timeEndPeriod(0);
}
return hTimer;
}
示例13: usleep
void usleep(DWORD waitTime)
{
if (waitTime >= 1000)
{
// Don't do long busy-waits.
// However much it seems like the QPC code would be more accurate,
// you can and probably will lose your time slice at any point during the wait,
// so we might as well voluntarily give up the CPU with a WaitForSingleObject.
HANDLE timer;
LARGE_INTEGER dueTime;
dueTime.QuadPart = -10 * (LONGLONG)waitTime;
timer = CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &dueTime, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
return;
}
LARGE_INTEGER perf_cnt, start, now;
QueryPerformanceFrequency(&perf_cnt);
QueryPerformanceCounter(&start);
do {
QueryPerformanceCounter((LARGE_INTEGER*) &now);
} while ((now.QuadPart - start.QuadPart) / (float)perf_cnt.QuadPart * 1000 * 1000 < waitTime);
}
示例14: freespace_private_discoveryThreadInit
int freespace_private_discoveryThreadInit() {
HANDLE thread;
if (freespace_instance_->window_ != NULL) {
return FREESPACE_ERROR_BUSY;
}
// Create the timer used to indicated device rescan is required.
freespace_instance_->discoveryEvent_ = CreateWaitableTimer(NULL, TRUE, NULL);
if (freespace_instance_->discoveryEvent_ == NULL) {
return FREESPACE_ERROR_UNEXPECTED;
}
// Need to scan a first time.
freespace_instance_->needToRescanDevicesFlag_ = TRUE;
// Create the hidden window
freespace_instance_->discoveryTheadStatus_ = FREESPACE_SUCCESS;
thread = CreateThread(NULL, 0, discoveryWindow, NULL, 0, NULL);
if (thread == NULL) {
freespace_instance_->discoveryTheadStatus_ = FREESPACE_ERROR_COULD_NOT_CREATE_THREAD;
return FREESPACE_ERROR_COULD_NOT_CREATE_THREAD;
}
return FREESPACE_SUCCESS;
}
示例15: defined
void
Delay::waitNsec(uint64_t nsec)
{
// POSIX.
#if defined(DUNE_SYS_HAS_CLOCK_NANOSLEEP) || defined(DUNE_SYS_HAS_NANOSLEEP)
timespec ts;
ts.tv_sec = nsec / c_nsec_per_sec;
ts.tv_nsec = nsec - (ts.tv_sec * c_nsec_per_sec);
# if defined(DUNE_SYS_HAS_CLOCK_NANOSLEEP)
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, 0);
# else
nanosleep(&ts, 0);
# endif
// Microsoft Windows.
#elif defined(DUNE_SYS_HAS_CREATE_WAITABLE_TIMER)
HANDLE t = CreateWaitableTimer(0, TRUE, 0);
LARGE_INTEGER dl;
dl.QuadPart = (uint64_t)nsec / 100;
// Negative value means relative time.
dl.QuadPart *= -1;
SetWaitableTimer(t, &dl, 0, 0, 0, 0);
WaitForSingleObject(t, INFINITE);
CloseHandle(t);
// Unsupported system.
#else
# error Delay::waitNsec() is not yet implemented in this system
#endif
}