【问题标题】:Windows function that works like: Linux queue_delayed_work( workq, dwork, delay)像这样工作的 Windows 函数:Linux queue_delayed_work(workq, dwork, delay)
【发布时间】:2012-07-11 17:33:16
【问题描述】:
Queue_delayed_work is a non blocking "timer" function which will queue `dwork` after `delay` jiffies.
我找不到任何非阻塞函数 WIN API,它的作用相同。
知道是否有某些功能,我不知道。或者如何实现这样的事情(一个非阻塞的“计时器”,它将在workq之后排队dwork至少delay jiffies。
【问题讨论】:
标签:
windows
queue
delayed-job
nonblocking
【解决方案1】:
对于 Linux 用户空间,
只有 teo 系统调用允许设置计时器,而不会同时阻塞事件的调用进程:
-timer_set_time
-Alarm
对于 Win 内核,
可以用KTIMER实现
KTIMER (Wdm.h)
KeInitializeTimer(PKTIMER Timer):
Timer: Pointer to a timer object, for which the caller provides the storage.
KeSetTimer (PKTIMER Timer, LARGE_INTEGER DueTimer, **PKDPC Dpc**)
对于 Win 用户空间,
可以用等待定时器对象实现:
BOOL SetWaitableTimer(
HANDLE hTimer, // handle to a timer object
const LARGE_INTEGER *pDueTime, // when timer will become signaled
LONG lPeriod, // periodic timer interval
PTIMERAPCROUTINE pfnCompletionRoutine, // pointer to the completion routine
LPVOID lpArgToCompletionRoutine, // data passed to the completion routine
BOOL fResume // flag for resume state
);