ReactOS  0.4.13-dev-455-g28ed234
timerqueue.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for timerqueue.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOL WINAPI BasepCreateDefaultTimerQueue (VOID)
 
BOOL WINAPI CancelTimerQueueTimer (IN HANDLE TimerQueue, IN HANDLE Timer)
 
BOOL WINAPI ChangeTimerQueueTimer (IN HANDLE TimerQueue, IN HANDLE Timer, IN ULONG DueTime, IN ULONG Period)
 
HANDLE WINAPI CreateTimerQueue (VOID)
 
BOOL WINAPI CreateTimerQueueTimer (OUT PHANDLE phNewTimer, IN HANDLE TimerQueue, IN WAITORTIMERCALLBACK Callback, IN PVOID Parameter, IN DWORD DueTime, IN DWORD Period, IN ULONG Flags)
 
BOOL WINAPI DeleteTimerQueue (IN HANDLE TimerQueue)
 
BOOL WINAPI DeleteTimerQueueEx (IN HANDLE TimerQueue, IN HANDLE CompletionEvent)
 
BOOL WINAPI DeleteTimerQueueTimer (IN HANDLE TimerQueue, IN HANDLE Timer, IN HANDLE CompletionEvent)
 
HANDLE WINAPI SetTimerQueueTimer (IN HANDLE TimerQueue, IN WAITORTIMERCALLBACK Callback, IN PVOID Parameter, IN DWORD DueTime, IN DWORD Period, IN BOOL PreferIo)
 

Variables

HANDLE BasepDefaultTimerQueue = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file timerqueue.c.

Function Documentation

◆ BasepCreateDefaultTimerQueue()

BOOL WINAPI BasepCreateDefaultTimerQueue ( VOID  )

Definition at line 25 of file timerqueue.c.

26 {
28 
29  /* Create the timer queue */
31  if (!NT_SUCCESS(Status))
32  {
34  DPRINT1("Unable to create the default timer queue!\n");
35  return FALSE;
36  }
37 
38  return TRUE;
39 }
#define TRUE
Definition: types.h:120
HANDLE BasepDefaultTimerQueue
Definition: timerqueue.c:18
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI RtlCreateTimerQueue(PHANDLE NewTimerQueue)
Definition: timerqueue.c:285
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8

Referenced by CreateTimerQueueTimer(), and SetTimerQueueTimer().

◆ CancelTimerQueueTimer()

BOOL WINAPI CancelTimerQueueTimer ( IN HANDLE  TimerQueue,
IN HANDLE  Timer 
)

Definition at line 49 of file timerqueue.c.

51 {
53 
54  if (!TimerQueue)
55  {
56  /* Use the default timer queue */
57  TimerQueue = BasepDefaultTimerQueue;
58  if (!TimerQueue)
59  {
60  /* A timer is being cancelled before one was created... fail */
62  return FALSE;
63  }
64  }
65 
66  /* Delete the timer */
67  Status = RtlDeleteTimer(TimerQueue, Timer, NULL);
68  if (!NT_SUCCESS(Status))
69  {
71  return FALSE;
72  }
73 
74  return TRUE;
75 }
#define TRUE
Definition: types.h:120
HANDLE BasepDefaultTimerQueue
Definition: timerqueue.c:18
NTSTATUS WINAPI RtlDeleteTimer(HANDLE TimerQueue, HANDLE Timer, HANDLE CompletionEvent)
Definition: timerqueue.c:520
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24

◆ ChangeTimerQueueTimer()

BOOL WINAPI ChangeTimerQueueTimer ( IN HANDLE  TimerQueue,
IN HANDLE  Timer,
IN ULONG  DueTime,
IN ULONG  Period 
)

Definition at line 82 of file timerqueue.c.

86 {
88 
89  if (!TimerQueue)
90  {
91  /* Use the default timer queue */
92  TimerQueue = BasepDefaultTimerQueue;
93  if (!TimerQueue)
94  {
95  /* A timer is being cancelled before one was created... fail */
97  return FALSE;
98  }
99  }
100 
101  /* Delete the timer */
102  Status = RtlUpdateTimer(TimerQueue, Timer, DueTime, Period);
103  if (!NT_SUCCESS(Status))
104  {
106  return FALSE;
107  }
108 
109  return TRUE;
110 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
HANDLE BasepDefaultTimerQueue
Definition: timerqueue.c:18
_In_ LARGE_INTEGER DueTime
Definition: kefuncs.h:524
LONG NTSTATUS
Definition: precomp.h:26
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1268
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24
NTSTATUS WINAPI RtlUpdateTimer(HANDLE TimerQueue, HANDLE Timer, DWORD DueTime, DWORD Period)
Definition: timerqueue.c:484

Referenced by test_timer_queue(), timer_queue_cb3(), and timer_queue_cb4().

◆ CreateTimerQueue()

HANDLE WINAPI CreateTimerQueue ( VOID  )

Definition at line 117 of file timerqueue.c.

118 {
119  HANDLE Handle;
121 
122  /* Create the timer queue */
124  if(!NT_SUCCESS(Status))
125  {
127  return NULL;
128  }
129 
130  return Handle;
131 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI RtlCreateTimerQueue(PHANDLE NewTimerQueue)
Definition: timerqueue.c:285
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
_In_ HANDLE Handle
Definition: extypes.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24

Referenced by test_timer_queue().

◆ CreateTimerQueueTimer()

BOOL WINAPI CreateTimerQueueTimer ( OUT PHANDLE  phNewTimer,
IN HANDLE  TimerQueue,
IN WAITORTIMERCALLBACK  Callback,
IN PVOID  Parameter,
IN DWORD  DueTime,
IN DWORD  Period,
IN ULONG  Flags 
)

Definition at line 138 of file timerqueue.c.

145 {
147 
148  /* Parameter is not optional -- clear it now */
149  *phNewTimer = NULL;
150 
151  /* Check if no queue was given */
152  if (!TimerQueue)
153  {
154  /* Create the queue if it didn't already exist */
156  {
157  return FALSE;
158  }
159 
160  /* Use the default queue */
161  TimerQueue = BasepDefaultTimerQueue;
162  }
163 
164  /* Create the timer. Note that no parameter checking is done here */
165  Status = RtlCreateTimer(TimerQueue,
166  phNewTimer,
167  Callback,
168  Parameter,
169  DueTime,
170  Period,
171  Flags);
172  if (!NT_SUCCESS(Status))
173  {
175  return FALSE;
176  }
177 
178  return TRUE;
179 }
#define TRUE
Definition: types.h:120
HANDLE BasepDefaultTimerQueue
Definition: timerqueue.c:18
_In_ LARGE_INTEGER DueTime
Definition: kefuncs.h:524
LONG NTSTATUS
Definition: precomp.h:26
BOOL WINAPI BasepCreateDefaultTimerQueue(VOID)
Definition: timerqueue.c:25
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1268
_In_ PVOID Parameter
Definition: ldrtypes.h:240
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS WINAPI RtlCreateTimer(HANDLE TimerQueue, PHANDLE NewTimer, WAITORTIMERCALLBACKFUNC Callback, PVOID Parameter, DWORD DueTime, DWORD Period, ULONG Flags)
Definition: timerqueue.c:425
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
LPFNPSPCALLBACK Callback
Definition: desk.c:111

Referenced by SHSetTimerQueueTimer(), Test1(), Test2(), Test3(), test_timer_queue(), and timer_queue_cb6().

◆ DeleteTimerQueue()

BOOL WINAPI DeleteTimerQueue ( IN HANDLE  TimerQueue)

Definition at line 186 of file timerqueue.c.

187 {
188  /* We don't allow the user to delete the default timer queue */
189  if (!TimerQueue)
190  {
192  return FALSE;
193  }
194 
195  /* Delete the timer queue */
196  RtlDeleteTimerQueueEx(TimerQueue, 0);
197  return TRUE;
198 }
#define TRUE
Definition: types.h:120
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
NTSTATUS WINAPI RtlDeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
Definition: timerqueue.c:331
#define SetLastError(x)
Definition: compat.h:409

◆ DeleteTimerQueueEx()

BOOL WINAPI DeleteTimerQueueEx ( IN HANDLE  TimerQueue,
IN HANDLE  CompletionEvent 
)

Definition at line 205 of file timerqueue.c.

207 {
209 
210  /* We don't allow the user to delete the default timer queue */
211  if (!TimerQueue)
212  {
214  return FALSE;
215  }
216 
217  /* Delete the timer queue */
218  Status = RtlDeleteTimerQueueEx(TimerQueue, CompletionEvent);
219  if (((CompletionEvent != INVALID_HANDLE_VALUE) && (Status == STATUS_PENDING)) ||
220  !(NT_SUCCESS(Status)))
221  {
222  /* In case CompletionEvent == NULL, RtlDeleteTimerQueueEx() returns before
223  all callback routines returned. We set the last error code to STATUS_PENDING
224  and return FALSE. In case CompletionEvent == INVALID_HANDLE_VALUE we only
225  can get here if another error occured. In case CompletionEvent is something
226  else, we get here and fail, even though it isn't really an error (if Status == STATUS_PENDING).
227  We also handle all other failures the same way. */
229  return FALSE;
230  }
231 
232  return TRUE;
233 }
#define TRUE
Definition: types.h:120
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
NTSTATUS WINAPI RtlDeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
Definition: timerqueue.c:331
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24

Referenced by test_timer_queue().

◆ DeleteTimerQueueTimer()

BOOL WINAPI DeleteTimerQueueTimer ( IN HANDLE  TimerQueue,
IN HANDLE  Timer,
IN HANDLE  CompletionEvent 
)

Definition at line 240 of file timerqueue.c.

243 {
245 
246  if (!TimerQueue)
247  {
248  /* Use the default timer queue */
249  TimerQueue = BasepDefaultTimerQueue;
250  if (!TimerQueue)
251  {
252  /* A timer is being cancelled before one was created... fail */
254  return FALSE;
255  }
256  }
257 
258  /* Delete the timer */
259  Status = RtlDeleteTimer(TimerQueue, Timer, CompletionEvent);
260  if (((CompletionEvent != INVALID_HANDLE_VALUE) && (Status == STATUS_PENDING)) ||
261  !(NT_SUCCESS(Status)))
262  {
263  /* In case CompletionEvent == NULL, RtlDeleteTimerQueueEx() returns before
264  all callback routines returned. We set the last error code to STATUS_PENDING
265  and return FALSE. In case CompletionEvent == INVALID_HANDLE_VALUE we only
266  can get here if another error occured. In case CompletionEvent is something
267  else, we get here and fail, even though it isn't really an error (if Status == STATUS_PENDING).
268  We also handle all other failures the same way. */
270  return FALSE;
271  }
272 
273  return TRUE;
274 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
HANDLE BasepDefaultTimerQueue
Definition: timerqueue.c:18
NTSTATUS WINAPI RtlDeleteTimer(HANDLE TimerQueue, HANDLE Timer, HANDLE CompletionEvent)
Definition: timerqueue.c:520
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24

Referenced by Test2(), Test3(), test_timer_queue(), timer_queue_cb2(), timer_queue_cb6(), and TimerCallback1().

◆ SetTimerQueueTimer()

HANDLE WINAPI SetTimerQueueTimer ( IN HANDLE  TimerQueue,
IN WAITORTIMERCALLBACK  Callback,
IN PVOID  Parameter,
IN DWORD  DueTime,
IN DWORD  Period,
IN BOOL  PreferIo 
)

Definition at line 281 of file timerqueue.c.

287 {
288  HANDLE Timer;
290 
291  /* Check if no queue was given */
292  if (!TimerQueue)
293  {
294  /* Create the queue if it didn't already exist */
296  {
297  return FALSE;
298  }
299 
300  /* Use the default queue */
301  TimerQueue = BasepDefaultTimerQueue;
302  }
303 
304  /* Create the timer */
305  Status = RtlCreateTimer(TimerQueue,
306  &Timer,
307  Callback,
308  Parameter,
309  DueTime,
310  Period,
312  if (!NT_SUCCESS(Status))
313  {
315  return NULL;
316  }
317 
318  return Timer;
319 }
HANDLE BasepDefaultTimerQueue
Definition: timerqueue.c:18
_In_ LARGE_INTEGER DueTime
Definition: kefuncs.h:524
LONG NTSTATUS
Definition: precomp.h:26
#define WT_EXECUTEINIOTHREAD
Definition: winnt_old.h:1072
BOOL WINAPI BasepCreateDefaultTimerQueue(VOID)
Definition: timerqueue.c:25
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1268
_In_ PVOID Parameter
Definition: ldrtypes.h:240
NTSTATUS WINAPI RtlCreateTimer(HANDLE TimerQueue, PHANDLE NewTimer, WAITORTIMERCALLBACKFUNC Callback, PVOID Parameter, DWORD DueTime, DWORD Period, ULONG Flags)
Definition: timerqueue.c:425
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
UINT Timer
Definition: capclock.c:11
LPFNPSPCALLBACK Callback
Definition: desk.c:111
#define WT_EXECUTEDEFAULT
Definition: winnt_old.h:1071

Variable Documentation

◆ BasepDefaultTimerQueue