ReactOS 0.4.16-dev-336-gb667d82
timerqueue.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Win32 Base API
3 * LICENSE: See COPYING in the top level directory
4 * FILE: dll/win32/kernel32/client/timerqueue.c
5 * PURPOSE: Timer Queue Functions
6 * PROGRAMMERS: Thomas Weidenmueller <w3seek@reactos.com>
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <k32.h>
12
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS ********************************************************************/
17
19
20/* PRIVATE FUNCTIONS **********************************************************/
21
22/* FIXME - make this thread safe */
23BOOL
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}
40
41/* PUBLIC FUNCTIONS ***********************************************************/
42
43
44/*
45 * @implemented
46 */
47BOOL
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}
76
77/*
78 * @implemented
79 */
80BOOL
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}
111
112/*
113 * @implemented
114 */
115HANDLE
116WINAPI
118{
121
122 /* Create the timer queue */
124 if(!NT_SUCCESS(Status))
125 {
127 return NULL;
128 }
129
130 return Handle;
131}
132
133/*
134 * @implemented
135 */
136BOOL
137WINAPI
139 IN HANDLE TimerQueue,
144 IN ULONG Flags)
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}
180
181/*
182 * @implemented
183 */
184BOOL
185WINAPI
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}
199
200/*
201 * @implemented
202 */
203BOOL
204WINAPI
206 IN HANDLE CompletionEvent)
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}
234
235/*
236 * @implemented
237 */
238BOOL
239WINAPI
242 IN HANDLE CompletionEvent)
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}
275
276/*
277 * @implemented
278 */
279HANDLE
280WINAPI
286 IN BOOL PreferIo)
287{
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}
320
321/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
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: timerqueue.c:138
HANDLE BasepDefaultTimerQueue
Definition: timerqueue.c:18
BOOL WINAPI BasepCreateDefaultTimerQueue(VOID)
Definition: timerqueue.c:25
HANDLE WINAPI CreateTimerQueue(VOID)
Definition: timerqueue.c:117
BOOL WINAPI DeleteTimerQueueEx(IN HANDLE TimerQueue, IN HANDLE CompletionEvent)
Definition: timerqueue.c:205
BOOL WINAPI DeleteTimerQueue(IN HANDLE TimerQueue)
Definition: timerqueue.c:186
HANDLE WINAPI SetTimerQueueTimer(IN HANDLE TimerQueue, IN WAITORTIMERCALLBACK Callback, IN PVOID Parameter, IN DWORD DueTime, IN DWORD Period, IN BOOL PreferIo)
Definition: timerqueue.c:281
BOOL WINAPI DeleteTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN HANDLE CompletionEvent)
Definition: timerqueue.c:240
BOOL WINAPI CancelTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer)
Definition: timerqueue.c:49
BOOL WINAPI ChangeTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN ULONG DueTime, IN ULONG Period)
Definition: timerqueue.c:82
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
static WAITORTIMERCALLBACK
Definition: thread.c:81
NTSYSAPI NTSTATUS NTAPI RtlCreateTimerQueue(PHANDLE TimerQueue)
Definition: timerqueue.c:285
NTSYSAPI NTSTATUS NTAPI RtlDeleteTimer(_In_ HANDLE TimerQueue, _In_ HANDLE Timer, _In_ HANDLE CompletionEvent)
NTSYSAPI NTSTATUS NTAPI RtlCreateTimer(_In_ HANDLE TimerQueue, _In_ PHANDLE phNewTimer, _In_ WAITORTIMERCALLBACKFUNC Callback, _In_ PVOID Parameter, _In_ ULONG DueTime, _In_ ULONG Period, _In_ ULONG Flags)
NTSYSAPI NTSTATUS NTAPI RtlDeleteTimerQueueEx(_In_ HANDLE TimerQueue, _In_opt_ HANDLE CompletionEvent)
NTSYSAPI NTSTATUS NTAPI RtlUpdateTimer(_In_ HANDLE TimerQueue, _In_ HANDLE Timer, _In_ ULONG DueTime, _In_ ULONG Period)
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
#define WINAPI
Definition: msvc.h:6
#define WT_EXECUTEINIOTHREAD
Definition: winnt_old.h:1068
#define WT_EXECUTEDEFAULT
Definition: winnt_old.h:1067
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1313
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336