00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
#include "ki.h"
00027
00028
00029
00030
00031
00032 LOGICAL
00033
FASTCALL
00034
KiInsertTimerTable (
00035 LARGE_INTEGER Interval,
00036 LARGE_INTEGER CurrentTime,
00037 IN
PRKTIMER Timer
00038 );
00039
00040 LOGICAL
00041
FASTCALL
00042 KiInsertTreeTimer (
00043 IN
PRKTIMER Timer,
00044 IN LARGE_INTEGER Interval
00045 )
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 {
00070
00071 LARGE_INTEGER CurrentTime;
00072 LARGE_INTEGER SystemTime;
00073 LARGE_INTEGER TimeDifference;
00074
00075
00076
00077
00078
00079
00080 Timer->Header.Inserted =
TRUE;
00081 Timer->Header.Absolute =
FALSE;
00082
if (Timer->Period == 0) {
00083 Timer->Header.SignalState =
FALSE;
00084 }
00085
00086
00087
00088
00089
00090
00091
if (Interval.HighPart >= 0) {
00092 KiQuerySystemTime(&SystemTime);
00093 TimeDifference.QuadPart = SystemTime.QuadPart - Interval.QuadPart;
00094
00095
00096
00097
00098
00099
00100
if (TimeDifference.HighPart >= 0) {
00101 Timer->Header.SignalState =
TRUE;
00102 Timer->Header.Inserted =
FALSE;
00103
return FALSE;
00104 }
00105
00106 Interval = TimeDifference;
00107 Timer->Header.Absolute =
TRUE;
00108 }
00109
00110
00111
00112
00113
00114
00115 KiQueryInterruptTime(&CurrentTime);
00116
return KiInsertTimerTable(Interval, CurrentTime, Timer);
00117 }
00118
00119 LOGICAL
00120
FASTCALL
00121 KiReinsertTreeTimer (
00122 IN
PRKTIMER Timer,
00123 IN ULARGE_INTEGER DueTime
00124 )
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 {
00148
00149 LARGE_INTEGER CurrentTime;
00150 LARGE_INTEGER Interval;
00151
00152
00153
00154
00155
00156
00157 Timer->Header.Inserted =
TRUE;
00158
if (Timer->Period == 0) {
00159 Timer->Header.SignalState =
FALSE;
00160 }
00161
00162
00163
00164
00165
00166
00167
00168 KiQueryInterruptTime(&CurrentTime);
00169 Interval.QuadPart = CurrentTime.QuadPart - DueTime.QuadPart;
00170
if (Interval.QuadPart >= 0) {
00171 Timer->Header.SignalState =
TRUE;
00172 Timer->Header.Inserted =
FALSE;
00173
return FALSE;
00174 }
00175
00176
00177
00178
00179
00180
return KiInsertTimerTable(Interval, CurrentTime, Timer);
00181 }
00182
00183 LOGICAL
00184
FASTCALL
00185 KiInsertTimerTable (
00186 LARGE_INTEGER Interval,
00187 LARGE_INTEGER CurrentTime,
00188 IN
PRKTIMER Timer
00189 )
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 {
00215
00216 ULONG
Index;
00217 PLIST_ENTRY ListHead;
00218 PLIST_ENTRY NextEntry;
00219
PRKTIMER NextTimer;
00220 ULONG SearchCount;
00221
00222
00223
00224
00225
00226
Index =
KiComputeTimerTableIndex(Interval, CurrentTime, Timer);
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 ListHead = &
KiTimerTableListHead[
Index];
00242 NextEntry = ListHead->Blink;
00243
00244
#if DBG
00245
00246 SearchCount = 0;
00247
00248
#endif
00249
00250
while (NextEntry != ListHead) {
00251
00252
00253
00254
00255
00256
#if DBG
00257
00258 SearchCount += 1;
00259
if (SearchCount >
KiMaximumSearchCount) {
00260
KiMaximumSearchCount = SearchCount;
00261 }
00262
00263
#endif
00264
00265 NextTimer = CONTAINING_RECORD(NextEntry,
KTIMER, TimerListEntry);
00266
if (((Timer->DueTime.HighPart == NextTimer->
DueTime.HighPart) &&
00267 (Timer->DueTime.LowPart >= NextTimer->
DueTime.LowPart)) ||
00268 (Timer->DueTime.HighPart > NextTimer->
DueTime.HighPart)) {
00269 InsertHeadList(NextEntry, &Timer->TimerListEntry);
00270
return TRUE;
00271 }
00272
00273 NextEntry = NextEntry->Blink;
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 InsertHeadList(ListHead, &Timer->TimerListEntry);
00290 KiQueryInterruptTime(&CurrentTime);
00291
if (((Timer->DueTime.HighPart == (ULONG)CurrentTime.HighPart) &&
00292 (Timer->DueTime.LowPart <= CurrentTime.LowPart)) ||
00293 (Timer->DueTime.HighPart < (ULONG)CurrentTime.HighPart)) {
00294
00295
00296
00297
00298
00299
00300
00301
KiRemoveTreeTimer(Timer);
00302 Timer->Header.SignalState =
TRUE;
00303 }
00304
00305
return Timer->Header.Inserted;
00306 }