Skip to content

Commit d104934

Browse files
committed
Properly Reset Deadlines when Rearming Timers
In the case where Windows schedules timers too early and CoreFoundation needs to rearm them, the deadlines need to be reset first else timers will not be rearmed properly.
1 parent 545cc23 commit d104934

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

CoreFoundation/RunLoop.subproj/CFRunLoop.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,6 +2938,13 @@ static int32_t __CFRunLoopRun(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFTimeInter
29382938
// In this case, the timer port has been automatically reset (since it was returned from MsgWaitForMultipleObjectsEx), and if we do not re-arm it, then no timers will ever be serviced again unless something adjusts the timer list (e.g. adding or removing timers). The fix for the issue is to reset the timer here if CFRunLoopDoTimers did not handle a timer itself. 9308754
29392939
if (!__CFRunLoopDoTimers(rl, rlm, mach_absolute_time())) {
29402940
// Re-arm the next timer
2941+
// Since we'll be resetting the same timer as before
2942+
// with the same deadlines, we need to reset these
2943+
// values so that the arm next timer code can
2944+
// correctly find the next timer in the list and arm
2945+
// the underlying timer.
2946+
rlm->_timerSoftDeadline = UINT64_MAX;
2947+
rlm->_timerHardDeadline = UINT64_MAX;
29412948
__CFArmNextTimerInMode(rlm, rl);
29422949
}
29432950
}

0 commit comments

Comments
 (0)