Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentimerqueue.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Win32 Base API 00003 * LICENSE: See COPYING in the top level directory 00004 * FILE: dll/win32/kernel32/client/timerqueue.c 00005 * PURPOSE: Timer Queue Functions 00006 * PROGRAMMERS: Thomas Weidenmueller <w3seek@reactos.com> 00007 */ 00008 00009 /* INCLUDES *******************************************************************/ 00010 00011 #include <k32.h> 00012 00013 #define NDEBUG 00014 #include <debug.h> 00015 00016 /* GLOBALS ********************************************************************/ 00017 00018 HANDLE BasepDefaultTimerQueue = NULL; 00019 00020 /* PRIVATE FUNCTIONS **********************************************************/ 00021 00022 /* FIXME - make this thread safe */ 00023 BOOL 00024 WINAPI 00025 BasepCreateDefaultTimerQueue(VOID) 00026 { 00027 NTSTATUS Status; 00028 00029 /* Create the timer queue */ 00030 Status = RtlCreateTimerQueue(&BasepDefaultTimerQueue); 00031 if (!NT_SUCCESS(Status)) 00032 { 00033 BaseSetLastNTError(Status); 00034 DPRINT1("Unable to create the default timer queue!\n"); 00035 return FALSE; 00036 } 00037 00038 return TRUE; 00039 } 00040 00041 /* PUBLIC FUNCTIONS ***********************************************************/ 00042 00043 00044 /* 00045 * @implemented 00046 */ 00047 BOOL 00048 WINAPI 00049 CancelTimerQueueTimer(IN HANDLE TimerQueue, 00050 IN HANDLE Timer) 00051 { 00052 NTSTATUS Status; 00053 00054 if (!TimerQueue) 00055 { 00056 /* Use the default timer queue */ 00057 TimerQueue = BasepDefaultTimerQueue; 00058 if (!TimerQueue) 00059 { 00060 /* A timer is being cancelled before one was created... fail */ 00061 SetLastError(ERROR_INVALID_HANDLE); 00062 return FALSE; 00063 } 00064 } 00065 00066 /* Delete the timer */ 00067 Status = RtlDeleteTimer(TimerQueue, Timer, NULL); 00068 if (!NT_SUCCESS(Status)) 00069 { 00070 BaseSetLastNTError(Status); 00071 return FALSE; 00072 } 00073 00074 return TRUE; 00075 } 00076 00077 /* 00078 * @implemented 00079 */ 00080 BOOL 00081 WINAPI 00082 ChangeTimerQueueTimer(IN HANDLE TimerQueue, 00083 IN HANDLE Timer, 00084 IN ULONG DueTime, 00085 IN ULONG Period) 00086 { 00087 NTSTATUS Status; 00088 00089 if (!TimerQueue) 00090 { 00091 /* Use the default timer queue */ 00092 TimerQueue = BasepDefaultTimerQueue; 00093 if (!TimerQueue) 00094 { 00095 /* A timer is being cancelled before one was created... fail */ 00096 SetLastError(ERROR_INVALID_PARAMETER); 00097 return FALSE; 00098 } 00099 } 00100 00101 /* Delete the timer */ 00102 Status = RtlUpdateTimer(TimerQueue, Timer, DueTime, Period); 00103 if (!NT_SUCCESS(Status)) 00104 { 00105 BaseSetLastNTError(Status); 00106 return FALSE; 00107 } 00108 00109 return TRUE; 00110 } 00111 00112 /* 00113 * @implemented 00114 */ 00115 HANDLE 00116 WINAPI 00117 CreateTimerQueue(VOID) 00118 { 00119 HANDLE Handle; 00120 NTSTATUS Status; 00121 00122 /* Create the timer queue */ 00123 Status = RtlCreateTimerQueue(&Handle); 00124 if(!NT_SUCCESS(Status)) 00125 { 00126 BaseSetLastNTError(Status); 00127 return NULL; 00128 } 00129 00130 return Handle; 00131 } 00132 00133 /* 00134 * @implemented 00135 */ 00136 BOOL 00137 WINAPI 00138 CreateTimerQueueTimer(OUT PHANDLE phNewTimer, 00139 IN HANDLE TimerQueue, 00140 IN WAITORTIMERCALLBACK Callback, 00141 IN PVOID Parameter, 00142 IN DWORD DueTime, 00143 IN DWORD Period, 00144 IN ULONG Flags) 00145 { 00146 NTSTATUS Status; 00147 00148 /* Parameter is not optional -- clear it now */ 00149 *phNewTimer = NULL; 00150 00151 /* Check if no queue was given */ 00152 if (!TimerQueue) 00153 { 00154 /* Create the queue if it didn't already exist */ 00155 if (!(BasepDefaultTimerQueue) && !(BasepCreateDefaultTimerQueue())) 00156 { 00157 return FALSE; 00158 } 00159 00160 /* Use the default queue */ 00161 TimerQueue = BasepDefaultTimerQueue; 00162 } 00163 00164 /* Create the timer. Note that no parameter checking is done here */ 00165 Status = RtlCreateTimer(TimerQueue, 00166 phNewTimer, 00167 Callback, 00168 Parameter, 00169 DueTime, 00170 Period, 00171 Flags); 00172 if (!NT_SUCCESS(Status)) 00173 { 00174 BaseSetLastNTError(Status); 00175 return FALSE; 00176 } 00177 00178 return TRUE; 00179 } 00180 00181 /* 00182 * @implemented 00183 */ 00184 BOOL 00185 WINAPI 00186 DeleteTimerQueue(IN HANDLE TimerQueue) 00187 { 00188 /* We don't allow the user to delete the default timer queue */ 00189 if (!TimerQueue) 00190 { 00191 SetLastError(ERROR_INVALID_HANDLE); 00192 return FALSE; 00193 } 00194 00195 /* Delete the timer queue */ 00196 RtlDeleteTimerQueueEx(TimerQueue, 0); 00197 return TRUE; 00198 } 00199 00200 /* 00201 * @implemented 00202 */ 00203 BOOL 00204 WINAPI 00205 DeleteTimerQueueEx(IN HANDLE TimerQueue, 00206 IN HANDLE CompletionEvent) 00207 { 00208 NTSTATUS Status; 00209 00210 /* We don't allow the user to delete the default timer queue */ 00211 if (!TimerQueue) 00212 { 00213 SetLastError(ERROR_INVALID_HANDLE); 00214 return FALSE; 00215 } 00216 00217 /* Delete the timer queue */ 00218 Status = RtlDeleteTimerQueueEx(TimerQueue, CompletionEvent); 00219 if (((CompletionEvent != INVALID_HANDLE_VALUE) && (Status == STATUS_PENDING)) || 00220 !(NT_SUCCESS(Status))) 00221 { 00222 /* In case CompletionEvent == NULL, RtlDeleteTimerQueueEx() returns before 00223 all callback routines returned. We set the last error code to STATUS_PENDING 00224 and return FALSE. In case CompletionEvent == INVALID_HANDLE_VALUE we only 00225 can get here if another error occured. In case CompletionEvent is something 00226 else, we get here and fail, even though it isn't really an error (if Status == STATUS_PENDING). 00227 We also handle all other failures the same way. */ 00228 BaseSetLastNTError(Status); 00229 return FALSE; 00230 } 00231 00232 return TRUE; 00233 } 00234 00235 /* 00236 * @implemented 00237 */ 00238 BOOL 00239 WINAPI 00240 DeleteTimerQueueTimer(IN HANDLE TimerQueue, 00241 IN HANDLE Timer, 00242 IN HANDLE CompletionEvent) 00243 { 00244 NTSTATUS Status; 00245 00246 if (!TimerQueue) 00247 { 00248 /* Use the default timer queue */ 00249 TimerQueue = BasepDefaultTimerQueue; 00250 if (!TimerQueue) 00251 { 00252 /* A timer is being cancelled before one was created... fail */ 00253 SetLastError(ERROR_INVALID_PARAMETER); 00254 return FALSE; 00255 } 00256 } 00257 00258 /* Delete the timer */ 00259 Status = RtlDeleteTimer(TimerQueue, Timer, CompletionEvent); 00260 if (((CompletionEvent != INVALID_HANDLE_VALUE) && (Status == STATUS_PENDING)) || 00261 !(NT_SUCCESS(Status))) 00262 { 00263 /* In case CompletionEvent == NULL, RtlDeleteTimerQueueEx() returns before 00264 all callback routines returned. We set the last error code to STATUS_PENDING 00265 and return FALSE. In case CompletionEvent == INVALID_HANDLE_VALUE we only 00266 can get here if another error occured. In case CompletionEvent is something 00267 else, we get here and fail, even though it isn't really an error (if Status == STATUS_PENDING). 00268 We also handle all other failures the same way. */ 00269 BaseSetLastNTError(Status); 00270 return FALSE; 00271 } 00272 00273 return TRUE; 00274 } 00275 00276 /* 00277 * @implemented 00278 */ 00279 HANDLE 00280 WINAPI 00281 SetTimerQueueTimer(IN HANDLE TimerQueue, 00282 IN WAITORTIMERCALLBACK Callback, 00283 IN PVOID Parameter, 00284 IN DWORD DueTime, 00285 IN DWORD Period, 00286 IN BOOL PreferIo) 00287 { 00288 HANDLE Timer; 00289 NTSTATUS Status; 00290 00291 /* Check if no queue was given */ 00292 if (!TimerQueue) 00293 { 00294 /* Create the queue if it didn't already exist */ 00295 if (!(BasepDefaultTimerQueue) && !(BasepCreateDefaultTimerQueue())) 00296 { 00297 return FALSE; 00298 } 00299 00300 /* Use the default queue */ 00301 TimerQueue = BasepDefaultTimerQueue; 00302 } 00303 00304 /* Create the timer */ 00305 Status = RtlCreateTimer(TimerQueue, 00306 &Timer, 00307 Callback, 00308 Parameter, 00309 DueTime, 00310 Period, 00311 PreferIo ? WT_EXECUTEINIOTHREAD : WT_EXECUTEDEFAULT); 00312 if (!NT_SUCCESS(Status)) 00313 { 00314 BaseSetLastNTError(Status); 00315 return NULL; 00316 } 00317 00318 return Timer; 00319 } 00320 00321 /* EOF */ Generated on Mon May 28 2012 04:24:10 for ReactOS by
1.7.6.1
|