ReactOS 0.4.15-dev-8135-g1bc6c90
mxtimerkm.h
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5ModuleName:
6
7 MxTimerKm.h
8
9Abstract:
10
11 Kernel mode implementation of timer defined in
12 MxTimer.h
13
14Author:
15
16
17Revision History:
18
19
20
21--*/
22
23#pragma once
24
25#define TolerableDelayUnlimited ((ULONG)-1)
26
27typedef
35 );
36
37typedef struct _MdTimer {
38
39
40 //
41 // The timer period
42 //
44
45 //
46 // Tracks whether the ex timer is being used
47 //
49
50// #pragma warning(push)
51// #pragma warning( disable: 4201 ) // nonstandard extension used : nameless struct/union
52
53 union {
54 struct {
55 //
56 // Callback function to be invoked upon timer expiration
57 //
61 };
62
63 struct {
64 //
65 // Callback function to be invoked upon timer expiration
66 //
69 };
70 };
71
72// #pragma warning(pop)
73
74 //
75 // Context to be passed in to the callback function
76 //
78
80
81#include "mxtimer.h"
82
84 VOID
85 )
86{
89 m_Timer.m_Period = 0;
91}
92
94 VOID
95 )
96{
97 // __REACTOS__ Ex timers are not supported
98 // BOOLEAN wasCancelled;
99
100 // if (m_Timer.m_IsExtTimer &&
101 // m_Timer.m_KernelExTimer) {
102 // wasCancelled = ExDeleteTimer(m_Timer.m_KernelExTimer,
103 // TRUE, // Cancel if pending. We don't expect
104 // // it to be pending though
105 // FALSE,// Wait
106 // NULL);
107 // //
108 // // Timer should not have been pending
109 // //
110 // ASSERT(wasCancelled == FALSE);
111 // m_Timer.m_KernelExTimer = NULL;
112 // }
113}
114
116#ifdef _MSC_VER
117#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "_Must_inspect_result_ not needed in kernel mode as the function always succeeds");
118#endif
121 __in MdDeferredRoutine TimerCallback,
123 )
124{
126 m_Timer.m_TimerCallback = TimerCallback;
128
130 KeInitializeDpc(&(m_Timer.TimerDpc), // Timer DPC
131 m_Timer.m_TimerCallback, // DeferredRoutine
132 m_Timer.m_TimerContext); // DeferredContext
133
135
136 return STATUS_SUCCESS;
137}
138
143 __in MdExtCallback TimerCallback,
146 __in BOOLEAN UseHighResolutionTimer
147 )
148/*++
149
150Routine Description:
151
152 Initializes an Ex timer. By invoking this routine instead of
153 Initialize, the client is implicitly declaring that it wants
154 to use the new timers
155
156Arguments:
157
158 TimerContext - Context to be passed back with the cllback
159 TimerCallback - Callback to be invoked when the timer fires
160 Period - Period in ms
161 TolerableDelay - Tolerable delay in ms
162 UseHighResolutionTimer- Indicates whether to use the high
163 resolution timers
164
165Returns:
166
167 Status
168
169--*/
170
171{
172 // NTSTATUS status;
173 // ULONG attributes = 0;
174
175 // m_Timer.m_TimerContext = TimerContext;
176 // m_Timer.m_ExTimerCallback = TimerCallback;
177 // m_Timer.m_Period = Period;
178
179 // if (TolerableDelay != 0) {
180
181 // attributes |= EX_TIMER_NO_WAKE;
182
183 // } else if (UseHighResolutionTimer) {
184
185 // attributes |= EX_TIMER_HIGH_RESOLUTION;
186 // }
187
188 // m_Timer.m_KernelExTimer = ExAllocateTimer(m_Timer.m_ExTimerCallback,
189 // TimerContext,
190 // attributes);
191 // if (m_Timer.m_KernelExTimer) {
192
193 // status = STATUS_SUCCESS;
194
195 // } else {
196
197 // status = STATUS_INSUFFICIENT_RESOURCES;
198 // }
199
200 // m_Timer.m_IsExtTimer = TRUE;
201
202 // return status;
203 return STATUS_NOT_IMPLEMENTED; // __REACTOS__ Ex timers are not supported
204}
205
206
207__inline
212 )
213{
214 if (m_Timer.m_IsExtTimer) {
215 // __REACTOS__ Ex timers are not supported
216 // EXT_SET_PARAMETERS parameters;
217
218 // ExInitializeSetTimerParameters(&parameters);
219
220 // //
221 // // We get the delay in ms but the underlying API needs it in 100 ns
222 // // units. Convert tolerable delay from ms to 100 ns. However,
223 // // MAXULONG (TolerableDelayUnlimited) has a special meaning that the
224 // // system should never be woken up, so we assign the corresponding
225 // // special value for Ex timers
226 // //
227 // if (TolerableDelay == TolerableDelayUnlimited) {
228 // parameters.NoWakeTolerance = EX_TIMER_UNLIMITED_TOLERANCE;
229 // } else {
230 // parameters.NoWakeTolerance = ((LONGLONG) TolerableDelay) * 10 * 1000;
231 // }
232
233 // return ExSetTimer(m_Timer.m_KernelExTimer,
234 // DueTime.QuadPart,
235 // (((LONGLONG) m_Timer.m_Period) * 10 * 1000),
236 // &parameters);
237 return FALSE;
238 } else {
239
240 return KeSetCoalescableTimer(&(m_Timer.KernelTimer),
241 DueTime,
244 &(m_Timer.TimerDpc));
245 }
246
247}
248
249
250VOID
254 )
255{
256 if (m_Timer.m_IsExtTimer) {
257
259
260 } else {
261 KeSetCoalescableTimer(&(m_Timer.KernelTimer),
262 DueTime,
265 &(m_Timer.TimerDpc));
266 }
267
268 return;
269}
270
274 VOID
275 )
276{
277 BOOLEAN bRetVal;
278
279 if (m_Timer.m_IsExtTimer) {
280 bRetVal = FALSE;
281 // bRetVal = ExCancelTimer(m_Timer.m_KernelExTimer, NULL); // __REACTOS__ Ex timers are not supported
282
283 } else {
284 bRetVal = KeCancelTimer(&(m_Timer.KernelTimer));
285 }
286
287 return bRetVal;
288}
289
290VOID
292 VOID
293 )
294{
296}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
__inline MxTimer(VOID)
Definition: mxtimerkm.h:83
CHECK_RETURN_IF_USER_MODE __inline NTSTATUS InitializeEx(__in_opt PVOID TimerContext, __in MdExtCallbackType TimerCallback, __in LONG Period, __in ULONG TolerableDelay, __in BOOLEAN UseHighResolutionTimer)
Definition: mxtimerkm.h:141
__inline ~MxTimer(VOID)
Definition: mxtimerkm.h:93
_Must_inspect_result_ __inline BOOLEAN Stop(VOID)
Definition: mxtimerkm.h:273
__inline VOID Start(__in LARGE_INTEGER DueTime, __in ULONG TolerableDelay=0)
Definition: mxtimerkm.h:251
__inline VOID FlushQueuedDpcs(VOID)
Definition: mxtimerkm.h:291
CHECK_RETURN_IF_USER_MODE __inline NTSTATUS Initialize(__in_opt PVOID TimerContext, __in MdDeferredRoutine TimerCallback, __in LONG Period)
Definition: mxtimerkm.h:119
MdTimer m_Timer
Definition: mxtimer.h:33
__inline BOOLEAN StartWithReturn(__in LARGE_INTEGER DueTime, __in ULONG TolerableDelay=0)
Definition: mxtimerkm.h:209
static __inline VOID MxFlushQueuedDpcs()
Definition: mxgeneralkm.h:589
#define __in
Definition: dbghelp.h:35
#define __inout
Definition: dbghelp.h:50
#define __in_opt
Definition: dbghelp.h:38
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define _Must_inspect_result_
Definition: ms_sal.h:558
KDEFERRED_ROUTINE * MdDeferredRoutine
Definition: mxkm.h:35
EXT_CALLBACK * MdExtCallback
Definition: mxkm.h:36
struct _MdTimer MdTimer
BOOLEAN(STDCALL * PFN_KE_SET_COALESCABLE_TIMER)(__inout PKTIMER Timer, __in LARGE_INTEGER DueTime, __in ULONG Period, __in ULONG TolerableDelay, __in_opt PKDPC Dpc)
Definition: mxtimerkm.h:29
@ NotificationTimer
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define BOOLEAN
Definition: pedump.c:73
long LONG
Definition: pedump.c:60
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: ketypes.h:699
KDPC TimerDpc
Definition: mxtimerkm.h:60
PEX_TIMER m_KernelExTimer
Definition: mxtimerkm.h:68
LONG m_Period
Definition: mxtimerkm.h:43
KTIMER KernelTimer
Definition: mxtimerkm.h:59
MdExtCallback m_ExTimerCallback
Definition: mxtimerkm.h:67
BOOLEAN m_IsExtTimer
Definition: mxtimerkm.h:48
MdDeferredRoutine m_TimerCallback
Definition: mxtimerkm.h:58
PVOID m_TimerContext
Definition: mxtimerkm.h:77
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
uint32_t ULONG
Definition: typedefs.h:59
#define STDCALL
Definition: wdf.h:45
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
struct _EX_TIMER * PEX_TIMER
Definition: extypes.h:291
_In_ LARGE_INTEGER _In_ ULONG _In_ ULONG TolerableDelay
Definition: kefuncs.h:1314
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1313
_In_ PLARGE_INTEGER _In_opt_ PTIMER_APC_ROUTINE _In_opt_ PVOID TimerContext
Definition: zwfuncs.h:430