@@ -48,15 +48,6 @@ extern void objc_terminate(void);
48
48
#define USE_DISPATCH_SOURCE_FOR_TIMERS 0
49
49
#endif
50
50
51
- static inline uint64_t __CFNanosecondsToTSR (uint64_t ns ) {
52
- #if TARGET_OS_MAC || TARGET_OS_LINUX
53
- return ns ;
54
- #else
55
- CFTimeInterval ti = ns / 1.0E9 ;
56
- return __CFTimeIntervalToTSR (ti );
57
- #endif
58
- }
59
-
60
51
#if USE_DISPATCH_SOURCE_FOR_TIMERS
61
52
#if !TARGET_OS_MAC
62
53
typedef uint32_t mach_port_t ;
@@ -2408,10 +2399,10 @@ static void __CFArmNextTimerInMode(CFRunLoopModeRef rlm, CFRunLoopRef rl) {
2408
2399
2409
2400
if (nextSoftDeadline < UINT64_MAX && (nextHardDeadline != rlm -> _timerHardDeadline || nextSoftDeadline != rlm -> _timerSoftDeadline )) {
2410
2401
if (CFRUNLOOP_NEXT_TIMER_ARMED_ENABLED ()) {
2411
- CFRUNLOOP_NEXT_TIMER_ARMED ((unsigned long )(nextSoftDeadline - __CFNanosecondsToTSR ( mach_absolute_time () )));
2402
+ CFRUNLOOP_NEXT_TIMER_ARMED ((unsigned long )(nextSoftDeadline - mach_absolute_time ()));
2412
2403
}
2413
2404
2414
- cf_trace (KDEBUG_EVENT_CFRL_NEXT_TIMER_ARMED , rl , rlm , (nextSoftDeadline - __CFNanosecondsToTSR ( mach_absolute_time () )), 0 );
2405
+ cf_trace (KDEBUG_EVENT_CFRL_NEXT_TIMER_ARMED , rl , rlm , (nextSoftDeadline - mach_absolute_time ()), 0 );
2415
2406
#if USE_DISPATCH_SOURCE_FOR_TIMERS
2416
2407
// We're going to hand off the range of allowable timer fire date to dispatch and let it fire when appropriate for the system.
2417
2408
uint64_t leeway = __CFTSRToNanoseconds (nextHardDeadline - nextSoftDeadline );
@@ -2508,7 +2499,7 @@ static Boolean __CFRunLoopDoTimer(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFRunLo
2508
2499
CFRetain (rlt );
2509
2500
__CFRunLoopTimerLock (rlt );
2510
2501
2511
- if (__CFIsValid (rlt ) && rlt -> _fireTSR <= __CFNanosecondsToTSR ( mach_absolute_time () ) && !__CFRunLoopTimerIsFiring (rlt ) && rlt -> _runLoop == rl ) {
2502
+ if (__CFIsValid (rlt ) && rlt -> _fireTSR <= mach_absolute_time () && !__CFRunLoopTimerIsFiring (rlt ) && rlt -> _runLoop == rl ) {
2512
2503
void * context_info = NULL ;
2513
2504
void (* context_release )(const void * ) = NULL ;
2514
2505
if (rlt -> _context .retain ) {
@@ -2585,7 +2576,7 @@ static Boolean __CFRunLoopDoTimer(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFRunLo
2585
2576
CRSetCrashLogMessage ("A CFRunLoopTimer with an interval of 0 is set to repeat" );
2586
2577
HALT ;
2587
2578
}
2588
- uint64_t currentTSR = __CFNanosecondsToTSR ( mach_absolute_time () );
2579
+ uint64_t currentTSR = mach_absolute_time ();
2589
2580
nextFireTSR = oldFireTSR ;
2590
2581
while (nextFireTSR <= currentTSR ) {
2591
2582
nextFireTSR += intervalTSR ;
@@ -2929,7 +2920,7 @@ static Boolean __CFRunLoopWaitForMultipleObjects(__CFPortSet portSet, HANDLE *on
2929
2920
2930
2921
/* rl, rlm are locked on entrance and exit */
2931
2922
static int32_t __CFRunLoopRun (CFRunLoopRef rl , CFRunLoopModeRef rlm , CFTimeInterval seconds , Boolean stopAfterHandle , CFRunLoopModeRef previousMode ) {
2932
- uint64_t startTSR = __CFNanosecondsToTSR ( mach_absolute_time () );
2923
+ uint64_t startTSR = mach_absolute_time ();
2933
2924
2934
2925
if (__CFRunLoopIsStopped (rl )) {
2935
2926
__CFRunLoopUnsetStopped (rl );
@@ -3186,7 +3177,7 @@ static int32_t __CFRunLoopRun(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFTimeInter
3186
3177
else if (modeQueuePort != MACH_PORT_NULL && livePort == modeQueuePort ) {
3187
3178
CFRUNLOOP_WAKEUP_FOR_TIMER ();
3188
3179
cf_trace (KDEBUG_EVENT_CFRL_DID_WAKEUP_FOR_TIMER , rl , rlm , livePort , 0 );
3189
- if (!__CFRunLoopDoTimers (rl , rlm , __CFNanosecondsToTSR ( mach_absolute_time () ))) {
3180
+ if (!__CFRunLoopDoTimers (rl , rlm , mach_absolute_time ())) {
3190
3181
// Re-arm the next timer, because we apparently fired early
3191
3182
__CFArmNextTimerInMode (rlm , rl );
3192
3183
}
@@ -3196,7 +3187,7 @@ static int32_t __CFRunLoopRun(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFTimeInter
3196
3187
CFRUNLOOP_WAKEUP_FOR_TIMER ();
3197
3188
// On Windows, we have observed an issue where the timer port is set before the time which we requested it to be set. For example, we set the fire time to be TSR 167646765860, but it is actually observed firing at TSR 167646764145, which is 1715 ticks early. The result is that, when __CFRunLoopDoTimers checks to see if any of the run loop timers should be firing, it appears to be 'too early' for the next timer, and no timers are handled.
3198
3189
// 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
3199
- if (!__CFRunLoopDoTimers (rl , rlm , __CFNanosecondsToTSR ( mach_absolute_time () ))) {
3190
+ if (!__CFRunLoopDoTimers (rl , rlm , mach_absolute_time ())) {
3200
3191
// Re-arm the next timer
3201
3192
// Since we'll be resetting the same timer as before
3202
3193
// with the same deadlines, we need to reset these
@@ -3270,7 +3261,7 @@ static int32_t __CFRunLoopRun(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFTimeInter
3270
3261
3271
3262
if (sourceHandledThisLoop && stopAfterHandle ) {
3272
3263
retVal = kCFRunLoopRunHandledSource ;
3273
- } else if (termTSR < __CFNanosecondsToTSR ( mach_absolute_time () )) {
3264
+ } else if (termTSR < mach_absolute_time ()) {
3274
3265
retVal = kCFRunLoopRunTimedOut ;
3275
3266
} else if (__CFRunLoopIsStopped (rl )) {
3276
3267
__CFRunLoopUnsetStopped (rl );
@@ -4527,7 +4518,7 @@ CFRunLoopTimerRef CFRunLoopTimerCreate(CFAllocatorRef allocator, CFAbsoluteTime
4527
4518
memory -> _tolerance = 0.0 ;
4528
4519
if (TIMER_DATE_LIMIT < fireDate ) fireDate = TIMER_DATE_LIMIT ;
4529
4520
memory -> _nextFireDate = fireDate ;
4530
- uint64_t now2 = __CFNanosecondsToTSR ( mach_absolute_time () );
4521
+ uint64_t now2 = mach_absolute_time ();
4531
4522
CFAbsoluteTime now1 = CFAbsoluteTimeGetCurrent ();
4532
4523
if (fireDate < now1 ) {
4533
4524
memory -> _fireTSR = now2 ;
@@ -4587,7 +4578,7 @@ void CFRunLoopTimerSetNextFireDate(CFRunLoopTimerRef rlt, CFAbsoluteTime fireDat
4587
4578
if (!__CFIsValid (rlt )) return ;
4588
4579
if (TIMER_DATE_LIMIT < fireDate ) fireDate = TIMER_DATE_LIMIT ;
4589
4580
uint64_t nextFireTSR = 0ULL ;
4590
- uint64_t now2 = __CFNanosecondsToTSR ( mach_absolute_time () );
4581
+ uint64_t now2 = mach_absolute_time ();
4591
4582
CFAbsoluteTime now1 = CFAbsoluteTimeGetCurrent ();
4592
4583
if (fireDate < now1 ) {
4593
4584
nextFireTSR = now2 ;
0 commit comments