File tree Expand file tree Collapse file tree 1 file changed +11
-13
lines changed Expand file tree Collapse file tree 1 file changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -168,24 +168,22 @@ private void ExitTimerCallback(object state)
168
168
// While there are exit times that are passed due still in the queue,
169
169
// exit the semaphore and dequeue the exit time.
170
170
int exitTime ;
171
- while ( _exitTimes . TryPeek ( out exitTime )
172
- && unchecked ( exitTime - Environment . TickCount ) <= 0 )
171
+ bool exitTimeValid = _exitTimes . TryPeek ( out exitTime ) ;
172
+ while ( exitTimeValid )
173
173
{
174
+ if ( unchecked ( exitTime - Environment . TickCount ) > 0 )
175
+ {
176
+ break ;
177
+ }
174
178
_semaphore . Release ( ) ;
175
179
_exitTimes . TryDequeue ( out exitTime ) ;
180
+ exitTimeValid = _exitTimes . TryPeek ( out exitTime ) ;
176
181
}
177
182
178
- // Try to get the next exit time from the queue and compute
179
- // the time until the next check should take place. If the
180
- // queue is empty, then no exit times will occur until at least
181
- // one time unit has passed.
182
- int timeUntilNextCheck ;
183
- if ( _exitTimes . TryPeek ( out exitTime ) )
184
- timeUntilNextCheck = unchecked ( exitTime - Environment . TickCount ) ;
185
- else
186
- timeUntilNextCheck = TimeUnitMilliseconds ;
187
-
188
- // Set the timer.
183
+ // we are already holding the next item from the queue, do not peek again
184
+ // although this exit time may have already pass by this stmt.
185
+ var timeUntilNextCheck = exitTimeValid ? Math . Min ( TimeUnitMilliseconds , Math . Max ( 0 , exitTime - Environment . TickCount ) ) : TimeUnitMilliseconds ;
186
+
189
187
_exitTimer . Change ( timeUntilNextCheck , - 1 ) ;
190
188
}
191
189
You can’t perform that action at this time.
0 commit comments