#region interface to native timer
private bool _isTimerScheduled;
- private int _currentTimerStartTicks;
+ private long _currentTimerStartTicks;
private uint _currentTimerDuration;
private bool EnsureTimerFiresBy(uint requestedDuration)
{
// The VM's timer implementation does not work well for very long-duration timers.
- // See kb 950807.
- // So we'll limit our native timer duration to a "small" value.
+ // So we limit our native timer duration to a "small" value.
// This may cause us to attempt to fire timers early, but that's ok -
// we'll just see that none of our timers has actually reached its due time,
// and schedule the native timer again.
if (_isTimerScheduled)
{
- uint elapsed = (uint)(TickCount - _currentTimerStartTicks);
+ long elapsed = TickCount64 - _currentTimerStartTicks;
if (elapsed >= _currentTimerDuration)
return true; //the timer's about to fire
- uint remainingDuration = _currentTimerDuration - elapsed;
+ uint remainingDuration = _currentTimerDuration - (uint)elapsed;
if (actualDuration >= remainingDuration)
return true; //the timer will fire earlier than this request
}
if (SetTimer(actualDuration))
{
_isTimerScheduled = true;
- _currentTimerStartTicks = TickCount;
+ _currentTimerStartTicks = TickCount64;
_currentTimerDuration = actualDuration;
return true;
}
// The current threshold, an absolute time where any timers scheduled to go off at or
// before this time must be queued to the short list.
- private int _currentAbsoluteThreshold = ShortTimersThresholdMilliseconds;
+ private long _currentAbsoluteThreshold = TickCount64 + ShortTimersThresholdMilliseconds;
// Default threshold that separates which timers target _shortTimers vs _longTimers. The threshold
// is chosen to balance the number of timers in the small list against the frequency with which
bool haveTimerToSchedule = false;
uint nextTimerDuration = uint.MaxValue;
- int nowTicks = TickCount;
+ long nowTicks = TickCount64;
// Sweep through the "short" timers. If the current tick count is greater than
// the current threshold, also sweep through the "long" timers. Finally, as part
// in our deleting or moving it; we'll continue after with this saved next timer.
TimerQueueTimer? next = timer._next;
- uint elapsed = (uint)(nowTicks - timer._startTicks);
- int remaining = (int)timer._dueTime - (int)elapsed;
+ long elapsed = nowTicks - timer._startTicks;
+ long remaining = timer._dueTime - elapsed;
if (remaining <= 0)
{
// Timer is ready to fire.
// again, meaning the timer can't keep up with the short period, have it fire 1 ms from now to
// avoid spinning without a delay.
timer._startTicks = nowTicks;
- uint elapsedForNextDueTime = elapsed - timer._dueTime;
+ long elapsedForNextDueTime = elapsed - timer._dueTime;
timer._dueTime = (elapsedForNextDueTime < timer._period) ?
- timer._period - elapsedForNextDueTime :
+ timer._period - (uint)elapsedForNextDueTime :
1;
// Update the timer if this becomes the next timer to fire.
// long list now; otherwise, most timers created in the interim would end up in the long
// list and we'd likely end up paying for another invocation of FireNextTimers that could
// have been delayed longer (to whatever is the current minimum in the long list).
- int remaining = _currentAbsoluteThreshold - nowTicks;
+ long remaining = _currentAbsoluteThreshold - nowTicks;
if (remaining > 0)
{
if (_shortTimers == null && _longTimers != null)
public bool UpdateTimer(TimerQueueTimer timer, uint dueTime, uint period)
{
- int nowTicks = TickCount;
+ long nowTicks = TickCount64;
// The timer can be put onto the short list if it's next absolute firing time
// is <= the current absolute threshold.
- int absoluteDueTime = (int)(nowTicks + dueTime);
+ long absoluteDueTime = nowTicks + dueTime;
bool shouldBeShort = _currentAbsoluteThreshold - absoluteDueTime >= 0;
if (timer._dueTime == Timeout.UnsignedInfinite)
internal bool _short;
// The time, according to TimerQueue.TickCount, when this timer's current interval started.
- internal int _startTicks;
+ internal long _startTicks;
// Timeout.UnsignedInfinite if we are not going to fire. Otherwise, the offset from _startTime when we will fire.
internal uint _dueTime;