ReactOS  0.4.15-dev-3428-g0609db5
_MdTimer Struct Reference

#include <mxtimerkm.h>

Collaboration diagram for _MdTimer:

Public Member Functions

 _MdTimer (VOID)
 
 ~_MdTimer (VOID)
 
BOOLEAN IsInSystemQueue (VOID)
 
_Must_inspect_result_ NTSTATUS Initialize (__in_opt PVOID TimerContext, __in MdDeferredRoutine TimerCallback, __in LONG Period)
 
BOOLEAN Start (__in LARGE_INTEGER DueTime, __in ULONG TolerableDelay)
 
_Must_inspect_result_ BOOLEAN Stop (VOID)
 
VOID TimerCallback (VOID)
 
BOOLEAN StartWithReturn (__in LARGE_INTEGER DueTime, __in ULONG TolerableDelay)
 

Static Public Member Functions

static VOID CALLBACK s_MdWorkCallback (__inout PTP_CALLBACK_INSTANCE Instance, __inout_opt PVOID Context, __inout PTP_WORK Work)
 
static VOID CALLBACK s_MdTimerCallback (__inout PTP_CALLBACK_INSTANCE Instance, __inout_opt PVOID Context, __inout PTP_TIMER Timer)
 

Public Attributes

LONG m_Period
 
BOOLEAN m_IsExtTimer
 
union {
   struct {
      MdDeferredRoutine   m_TimerCallback
 
      KTIMER   KernelTimer
 
      KDPC   TimerDpc
 
   } 
 
   struct {
      MdExtCallback   m_ExTimerCallback
 
      PEX_TIMER   m_KernelExTimer
 
   } 
 
}; 
 
PVOID m_TimerContext
 
PTP_TIMER m_TimerHandle
 
PTP_WORK m_WorkObject
 
BOOL m_CallbackStartedRunning
 
BOOL m_TimerWasStarted
 

Detailed Description

Definition at line 37 of file mxtimerkm.h.

Constructor & Destructor Documentation

◆ _MdTimer()

_MdTimer::_MdTimer ( VOID  )
inline

Definition at line 59 of file mxtimerum.h.

62  {
67  m_Period = 0;
70  }
PVOID m_TimerContext
Definition: mxtimerkm.h:77
BOOL m_CallbackStartedRunning
Definition: mxtimerum.h:51
MdDeferredRoutine m_TimerCallback
Definition: mxtimerkm.h:58
#define FALSE
Definition: types.h:117
PTP_WORK m_WorkObject
Definition: mxtimerum.h:46
BOOL m_TimerWasStarted
Definition: mxtimerum.h:57
LONG m_Period
Definition: mxtimerkm.h:43
#define NULL
Definition: types.h:112
PTP_TIMER m_TimerHandle
Definition: mxtimerum.h:41

◆ ~_MdTimer()

_MdTimer::~_MdTimer ( VOID  )
inline

Definition at line 72 of file mxtimerum.h.

75  {
76  //
77  // Release the timer object
78  //
79  if (m_TimerHandle)
80  {
81  CloseThreadpoolTimer(m_TimerHandle);
83  }
84 
85  //
86  // Release the work object
87  //
88  if (m_WorkObject)
89  {
90  CloseThreadpoolWork(m_WorkObject);
92  }
93  }
PTP_WORK m_WorkObject
Definition: mxtimerum.h:46
#define NULL
Definition: types.h:112
PTP_TIMER m_TimerHandle
Definition: mxtimerum.h:41

Member Function Documentation

◆ Initialize()

_Must_inspect_result_ NTSTATUS _MdTimer::Initialize ( __in_opt PVOID  TimerContext,
__in MdDeferredRoutine  TimerCallback,
__in LONG  Period 
)
inline

Definition at line 142 of file mxtimerum.h.

147  {
148  NTSTATUS ntStatus = STATUS_SUCCESS;
149 
152  m_Period = Period;
153 
154  //
155  // Create the timer object
156  //
157  m_TimerHandle = CreateThreadpoolTimer(_MdTimer::s_MdTimerCallback,
158  this,
159  NULL);
160  if (NULL == m_TimerHandle)
161  {
162  ntStatus = WinErrorToNtStatus(GetLastError());
163  }
164 
165  //
166  // Create the work object
167  //
168  if (NT_SUCCESS(ntStatus))
169  {
170  m_WorkObject = CreateThreadpoolWork(_MdTimer::s_MdWorkCallback,
171  this,
172  NULL);
173  if (NULL == m_WorkObject)
174  {
175  ntStatus = WinErrorToNtStatus(GetLastError());
176  }
177  }
178 
179  return ntStatus;
180  }
PVOID m_TimerContext
Definition: mxtimerkm.h:77
NTSTATUS WinErrorToNtStatus(__in ULONG WinError)
Definition: errtostatus.cpp:60
LONG NTSTATUS
Definition: precomp.h:26
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1324
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
MdDeferredRoutine m_TimerCallback
Definition: mxtimerkm.h:58
PTP_WORK m_WorkObject
Definition: mxtimerum.h:46
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static VOID CALLBACK s_MdTimerCallback(__inout PTP_CALLBACK_INSTANCE Instance, __inout_opt PVOID Context, __inout PTP_TIMER Timer)
Definition: mxtimerum.h:305
LONG m_Period
Definition: mxtimerkm.h:43
#define NULL
Definition: types.h:112
VOID TimerCallback(VOID)
Definition: mxtimerum.h:268
_In_ PLARGE_INTEGER _In_opt_ PTIMER_APC_ROUTINE _In_opt_ PVOID TimerContext
Definition: zwfuncs.h:428
static VOID CALLBACK s_MdWorkCallback(__inout PTP_CALLBACK_INSTANCE Instance, __inout_opt PVOID Context, __inout PTP_WORK Work)
Definition: mxtimerum.h:286
#define STATUS_SUCCESS
Definition: shellext.h:65
PTP_TIMER m_TimerHandle
Definition: mxtimerum.h:41

◆ IsInSystemQueue()

BOOLEAN _MdTimer::IsInSystemQueue ( VOID  )
inline

Definition at line 96 of file mxtimerum.h.

99  {
100  //
101  // Timer was not started since it was created or since
102  // it was last stopped, so it can't be in the system timer queue.
103  //
104  if (!m_TimerWasStarted) {
105  return FALSE;
106  }
107 
108  //
109  // Periodic timers are always in the system timer queue.
110  //
111  if (m_Period != 0) {
112  return TRUE;
113  }
114 
115  //
116  // Non-periodic timer:
117  //
118  // At this point, the timer callback function has either been canceled or
119  // has finished running. Examine the m_CallbackStartedRunning value to see
120  // which one of these happened.
121  //
123  {
124  //
125  // Timer cancellation was too late. Timer callback already started
126  // running and the timer was removed from the system timer queue.
127  //
128  return FALSE;
129  }
130  else
131  {
132  //
133  // Timer cancellation happened on time and prevented the timer callback
134  // from running.
135  //
136  return TRUE;
137  }
138  }
BOOL m_CallbackStartedRunning
Definition: mxtimerum.h:51
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL m_TimerWasStarted
Definition: mxtimerum.h:57
LONG m_Period
Definition: mxtimerkm.h:43

Referenced by Start(), and Stop().

◆ s_MdTimerCallback()

static VOID CALLBACK _MdTimer::s_MdTimerCallback ( __inout PTP_CALLBACK_INSTANCE  Instance,
__inout_opt PVOID  Context,
__inout PTP_TIMER  Timer 
)
inlinestatic

Definition at line 305 of file mxtimerum.h.

310  {
311  struct _MdTimer *pThis = NULL;
312 
315 
316  pThis = (struct _MdTimer*) Context;
317 
318  //
319  // First, indicate that the callback has started running
320  //
322 
323  //
324  // Post a work object to execute the callback function supplied by the
325  // user of MxTimer.
326  //
327  // We do not execute the user-supplied callback here because we could
328  // run into a deadlock if the user is trying to cancel the timer by
329  // calling MxTimer::Stop. MxTimer::Stop actually blocks waiting for
330  // MdTimer::s_MdTimerCallback to finish executing, so that it can know
331  // where its attempt to cancel the timer was successful. If we were to
332  // execute the user's callback in MdTimer::s_MdTimerCallback, the user
333  // would have to be careful not to call MxTimer::Stop while holding a
334  // lock that the user's callback tries to acquire. In order to avoid
335  // imposing such a restriction on the user, we allow
336  // MdTimer::s_MdTimerCallback to return immediately after posting a
337  // work object to run the user's callback.
338  //
339  SubmitThreadpoolWork(pThis->m_WorkObject);
340 
341  return;
342  }
BOOL m_CallbackStartedRunning
Definition: mxtimerum.h:51
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
PTP_WORK m_WorkObject
Definition: mxtimerum.h:46
#define NULL
Definition: types.h:112
IN PVOID Instance
Definition: pci.h:361

Referenced by Initialize().

◆ s_MdWorkCallback()

static VOID CALLBACK _MdTimer::s_MdWorkCallback ( __inout PTP_CALLBACK_INSTANCE  Instance,
__inout_opt PVOID  Context,
__inout PTP_WORK  Work 
)
inlinestatic

Definition at line 286 of file mxtimerum.h.

291  {
292  struct _MdTimer *pThis = NULL;
293 
296 
297  pThis = (struct _MdTimer*) Context;
298  pThis->TimerCallback();
299 
300  return;
301  }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define NULL
Definition: types.h:112
VOID TimerCallback(VOID)
Definition: mxtimerum.h:268
IN PVOID Instance
Definition: pci.h:361

Referenced by Initialize().

◆ Start()

BOOLEAN _MdTimer::Start ( __in LARGE_INTEGER  DueTime,
__in ULONG  TolerableDelay 
)
inline

Definition at line 183 of file mxtimerum.h.

187  {
188  BOOLEAN bRetVal;
189  FILETIME dueFileTime;
190 
191  if (m_TimerWasStarted) {
192  //
193  // Cancel the previously pended timer callback,
194  // we want it to execute after a full period elapsed.
195  //
196  WaitForThreadpoolTimerCallbacks(m_TimerHandle, TRUE);
197  }
198 
199  //
200  // Return TRUE if the timer is in the system timer queue.
201  //
202  bRetVal = IsInSystemQueue();
203 
204  //
205  // This is a fresh start for the timer, so clear the flag that the
206  // timer callback function may have previously set.
207  //
209 
210  //
211  // Set the timer started flag.
212  //
214 
215  //
216  // Copy the due time into a FILETIME structure
217  //
218  dueFileTime.dwLowDateTime = DueTime.LowPart;
219  dueFileTime.dwHighDateTime = (DWORD) DueTime.HighPart;
220 
221  //
222  // Start the timer
223  //
224  SetThreadpoolTimer(m_TimerHandle,
225  &dueFileTime,
226  (DWORD) m_Period,
228 
229  return bRetVal;
230  }
_In_ LARGE_INTEGER _In_ ULONG _In_ ULONG TolerableDelay
Definition: kefuncs.h:1324
BOOL m_CallbackStartedRunning
Definition: mxtimerum.h:51
#define TRUE
Definition: types.h:120
#define DWORD
Definition: nt_native.h:44
DWORD dwHighDateTime
Definition: mapidefs.h:66
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
BOOLEAN IsInSystemQueue(VOID)
Definition: mxtimerum.h:96
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL m_TimerWasStarted
Definition: mxtimerum.h:57
LONG m_Period
Definition: mxtimerkm.h:43
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
PTP_TIMER m_TimerHandle
Definition: mxtimerum.h:41
DWORD dwLowDateTime
Definition: mapidefs.h:65

Referenced by StartWithReturn().

◆ StartWithReturn()

BOOLEAN _MdTimer::StartWithReturn ( __in LARGE_INTEGER  DueTime,
__in ULONG  TolerableDelay 
)
inline

Definition at line 345 of file mxtimerum.h.

349  {
350  return Start(DueTime, TolerableDelay);
351  }
_In_ LARGE_INTEGER _In_ ULONG _In_ ULONG TolerableDelay
Definition: kefuncs.h:1324
BOOLEAN Start(__in LARGE_INTEGER DueTime, __in ULONG TolerableDelay)
Definition: mxtimerum.h:183
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187

◆ Stop()

_Must_inspect_result_ BOOLEAN _MdTimer::Stop ( VOID  )
inline

Definition at line 234 of file mxtimerum.h.

237  {
238  BOOLEAN bRetVal;
239 
240  bRetVal = IsInSystemQueue();
241 
242  //
243  // Stop the timer
244  //
245  SetThreadpoolTimer(m_TimerHandle,
246  NULL, // pftDueTime
247  0, // msPeriod
248  0 // msWindowLength
249  );
250 
251  //
252  // Cancel pending callbacks that have not yet started to execute and wait
253  // for outstanding callbacks to complete.
254  //
255  WaitForThreadpoolTimerCallbacks(m_TimerHandle,
256  TRUE // cancel pending callbacks
257  );
258 
259  //
260  // Reset the timer started flag.
261  //
263 
264  return bRetVal;
265  }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
BOOLEAN IsInSystemQueue(VOID)
Definition: mxtimerum.h:96
BOOL m_TimerWasStarted
Definition: mxtimerum.h:57
#define NULL
Definition: types.h:112
PTP_TIMER m_TimerHandle
Definition: mxtimerum.h:41

◆ TimerCallback()

VOID _MdTimer::TimerCallback ( VOID  )
inline

Definition at line 268 of file mxtimerum.h.

271  {
272  //
273  // Invoke the user's callback function
274  //
275  m_TimerCallback(NULL, /* Reserved1 */
277  NULL, /* Reserved2 */
278  NULL /* Reserved3 */
279  );
280 
281  return;
282  }
PVOID m_TimerContext
Definition: mxtimerkm.h:77
MdDeferredRoutine m_TimerCallback
Definition: mxtimerkm.h:58
#define NULL
Definition: types.h:112

Referenced by Initialize(), and s_MdWorkCallback().

Member Data Documentation

◆ @4509

union { ... }

◆ KernelTimer

KTIMER _MdTimer::KernelTimer

◆ m_CallbackStartedRunning

BOOL _MdTimer::m_CallbackStartedRunning

Definition at line 51 of file mxtimerum.h.

Referenced by _MdTimer(), IsInSystemQueue(), s_MdTimerCallback(), and Start().

◆ m_ExTimerCallback

MdExtCallback _MdTimer::m_ExTimerCallback

Definition at line 67 of file mxtimerkm.h.

◆ m_IsExtTimer

BOOLEAN _MdTimer::m_IsExtTimer

◆ m_KernelExTimer

PEX_TIMER _MdTimer::m_KernelExTimer

Definition at line 68 of file mxtimerkm.h.

Referenced by MxTimer::MxTimer().

◆ m_Period

◆ m_TimerCallback

MdDeferredRoutine _MdTimer::m_TimerCallback

◆ m_TimerContext

PVOID _MdTimer::m_TimerContext

◆ m_TimerHandle

PTP_TIMER _MdTimer::m_TimerHandle

Definition at line 41 of file mxtimerum.h.

Referenced by _MdTimer(), Initialize(), Start(), Stop(), and ~_MdTimer().

◆ m_TimerWasStarted

BOOL _MdTimer::m_TimerWasStarted

Definition at line 57 of file mxtimerum.h.

Referenced by _MdTimer(), IsInSystemQueue(), Start(), and Stop().

◆ m_WorkObject

PTP_WORK _MdTimer::m_WorkObject

Definition at line 46 of file mxtimerum.h.

Referenced by _MdTimer(), Initialize(), s_MdTimerCallback(), and ~_MdTimer().

◆ TimerDpc

KDPC _MdTimer::TimerDpc

Definition at line 60 of file mxtimerkm.h.

Referenced by MxTimer::Initialize(), MxTimer::Start(), and MxTimer::StartWithReturn().


The documentation for this struct was generated from the following files: