ReactOS 0.4.17-dev-966-gf06eace
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
22BOOL
25{
27 HANDLE TimerQueue;
28
29 /* Already initialized */
31 return TRUE;
32
33 /* Create the timer queue */
34 Status = RtlCreateTimerQueue(&TimerQueue);
35 if (!NT_SUCCESS(Status))
36 {
38 DPRINT1("Unable to create the default timer queue!\n");
39 return FALSE;
40 }
41
42 /* Try to publish it. If another thread already did, throw ours away */
44 TimerQueue,
45 NULL) != NULL)
46 {
47 RtlDeleteTimerQueueEx(TimerQueue, NULL);
48 }
49
50 return TRUE;
51}
52
53/* PUBLIC FUNCTIONS ***********************************************************/
54
55
56/*
57 * @implemented
58 */
59BOOL
63{
65
66 if (!TimerQueue)
67 {
68 /* Use the default timer queue */
69 TimerQueue = BasepDefaultTimerQueue;
70 if (!TimerQueue)
71 {
72 /* A timer is being cancelled before one was created... fail */
74 return FALSE;
75 }
76 }
77
78 /* Delete the timer */
79 Status = RtlDeleteTimer(TimerQueue, Timer, NULL);
80 if (!NT_SUCCESS(Status))
81 {
83 return FALSE;
84 }
85
86 return TRUE;
87}
88
89/*
90 * @implemented
91 */
92BOOL
98{
100
101 if (!TimerQueue)
102 {
103 /* Use the default timer queue */
104 TimerQueue = BasepDefaultTimerQueue;
105 if (!TimerQueue)
106 {
107 /* A timer is being cancelled before one was created... fail */
109 return FALSE;
110 }
111 }
112
113 /* Delete the timer */
114 Status = RtlUpdateTimer(TimerQueue, Timer, DueTime, Period);
115 if (!NT_SUCCESS(Status))
116 {
118 return FALSE;
119 }
120
121 return TRUE;
122}
123
124/*
125 * @implemented
126 */
127HANDLE
128WINAPI
130{
133
134 /* Create the timer queue */
136 if(!NT_SUCCESS(Status))
137 {
139 return NULL;
140 }
141
142 return Handle;
143}
144
145/*
146 * @implemented
147 */
148BOOL
149WINAPI
151 IN HANDLE TimerQueue,
156 IN ULONG Flags)
157{
159
160 /* Parameter is not optional -- clear it now */
161 *phNewTimer = NULL;
162
163 /* Check if no queue was given */
164 if (!TimerQueue)
165 {
166 /* Create the queue if it didn't already exist */
168 {
169 return FALSE;
170 }
171
172 /* Use the default queue */
173 TimerQueue = BasepDefaultTimerQueue;
174 }
175
176 /* Create the timer. Note that no parameter checking is done here */
177 Status = RtlCreateTimer(TimerQueue,
178 phNewTimer,
179 Callback,
180 Parameter,
181 DueTime,
182 Period,
183 Flags);
184 if (!NT_SUCCESS(Status))
185 {
187 return FALSE;
188 }
189
190 return TRUE;
191}
192
193/*
194 * @implemented
195 */
196BOOL
197WINAPI
199{
200 /* We don't allow the user to delete the default timer queue */
201 if (!TimerQueue)
202 {
204 return FALSE;
205 }
206
207 /* Delete the timer queue */
208 RtlDeleteTimerQueueEx(TimerQueue, 0);
209 return TRUE;
210}
211
212/*
213 * @implemented
214 */
215BOOL
216WINAPI
218 IN HANDLE CompletionEvent)
219{
221
222 /* We don't allow the user to delete the default timer queue */
223 if (!TimerQueue)
224 {
226 return FALSE;
227 }
228
229 /* Delete the timer queue */
230 Status = RtlDeleteTimerQueueEx(TimerQueue, CompletionEvent);
231 if (((CompletionEvent != INVALID_HANDLE_VALUE) && (Status == STATUS_PENDING)) ||
232 !(NT_SUCCESS(Status)))
233 {
234 /* In case CompletionEvent == NULL, RtlDeleteTimerQueueEx() returns before
235 all callback routines returned. We set the last error code to STATUS_PENDING
236 and return FALSE. In case CompletionEvent == INVALID_HANDLE_VALUE we only
237 can get here if another error occured. In case CompletionEvent is something
238 else, we get here and fail, even though it isn't really an error (if Status == STATUS_PENDING).
239 We also handle all other failures the same way. */
241 return FALSE;
242 }
243
244 return TRUE;
245}
246
247/*
248 * @implemented
249 */
250BOOL
251WINAPI
254 IN HANDLE CompletionEvent)
255{
257
258 if (!TimerQueue)
259 {
260 /* Use the default timer queue */
261 TimerQueue = BasepDefaultTimerQueue;
262 if (!TimerQueue)
263 {
264 /* A timer is being cancelled before one was created... fail */
266 return FALSE;
267 }
268 }
269
270 /* Delete the timer */
271 Status = RtlDeleteTimer(TimerQueue, Timer, CompletionEvent);
272 if (((CompletionEvent != INVALID_HANDLE_VALUE) && (Status == STATUS_PENDING)) ||
273 !(NT_SUCCESS(Status)))
274 {
275 /* In case CompletionEvent == NULL, RtlDeleteTimerQueueEx() returns before
276 all callback routines returned. We set the last error code to STATUS_PENDING
277 and return FALSE. In case CompletionEvent == INVALID_HANDLE_VALUE we only
278 can get here if another error occured. In case CompletionEvent is something
279 else, we get here and fail, even though it isn't really an error (if Status == STATUS_PENDING).
280 We also handle all other failures the same way. */
282 return FALSE;
283 }
284
285 return TRUE;
286}
287
288/*
289 * @implemented
290 */
291HANDLE
292WINAPI
298 IN BOOL PreferIo)
299{
302
303 /* Check if no queue was given */
304 if (!TimerQueue)
305 {
306 /* Create the queue if it didn't already exist */
308 {
309 return FALSE;
310 }
311
312 /* Use the default queue */
313 TimerQueue = BasepDefaultTimerQueue;
314 }
315
316 /* Create the timer */
317 Status = RtlCreateTimer(TimerQueue,
318 &Timer,
319 Callback,
320 Parameter,
321 DueTime,
322 Period,
324 if (!NT_SUCCESS(Status))
325 {
327 return NULL;
328 }
329
330 return Timer;
331}
332
333/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_In_ ULONG _In_ ULONG _In_opt_ DXGKCB_MIRACAST_SEND_MESSAGE_CALLBACK Callback
Definition: dispmprt.h:620
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#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:150
HANDLE BasepDefaultTimerQueue
Definition: timerqueue.c:18
BOOL WINAPI BasepCreateDefaultTimerQueue(VOID)
Definition: timerqueue.c:24
BOOL WINAPI DeleteTimerQueueEx(IN HANDLE TimerQueue, IN HANDLE CompletionEvent)
Definition: timerqueue.c:217
BOOL WINAPI DeleteTimerQueue(IN HANDLE TimerQueue)
Definition: timerqueue.c:198
HANDLE WINAPI SetTimerQueueTimer(IN HANDLE TimerQueue, IN WAITORTIMERCALLBACK Callback, IN PVOID Parameter, IN DWORD DueTime, IN DWORD Period, IN BOOL PreferIo)
Definition: timerqueue.c:293
BOOL WINAPI DeleteTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN HANDLE CompletionEvent)
Definition: timerqueue.c:252
BOOL WINAPI CancelTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer)
Definition: timerqueue.c:61
BOOL WINAPI ChangeTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN ULONG DueTime, IN ULONG Period)
Definition: timerqueue.c:94
HANDLE WINAPI DECLSPEC_HOTPATCH CreateTimerQueue(void)
Definition: sync.c:910
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:24
#define InterlockedCompareExchangePointer
Definition: interlocked.h:144
static WAITORTIMERCALLBACK
Definition: thread.c:84
NTSYSAPI NTSTATUS NTAPI RtlCreateTimerQueue(PHANDLE TimerQueue)
Definition: threadpool.c:864
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 STATUS_PENDING
Definition: telnetd.h:14
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
#define WINAPI
Definition: msvc.h:6
#define WT_EXECUTEINIOTHREAD
Definition: winnt_old.h:1097
#define WT_EXECUTEDEFAULT
Definition: winnt_old.h:1096
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1304
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336