- Timestamp:
- Mar 28, 2024 1:33:58 PM (10 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/darwin/time-darwin.cpp
r99127 r104105 48 48 #include <iprt/time.h> 49 49 #include <iprt/assert.h> 50 #include <iprt/asm-math.h> 50 51 #include "internal/time.h" 51 52 … … 55 56 *********************************************************************************************************************************/ 56 57 static struct mach_timebase_info g_Info = { 0, 0 }; 57 static double g_rdFactor = 0.0;58 58 static bool g_fFailedToGetTimeBaseInfo = false; 59 59 … … 66 66 struct mach_timebase_info Info; 67 67 if (mach_timebase_info(&Info) == KERN_SUCCESS) 68 {69 g_rdFactor = (double)Info.numer / (double)Info.denom;70 68 g_Info = Info; 71 }72 69 else 73 70 { 74 71 g_fFailedToGetTimeBaseInfo = true; 75 Assert(g_Info.denom == 0 && g_Info.numer == 0 && g_rdFactor == 0.0);72 Assert(g_Info.denom == 0 && g_Info.numer == 0); 76 73 } 77 74 } … … 88 85 rtTimeDarwinLazyInit(); 89 86 90 /* special case: absolute time is in nanoseconds */87 /* special case: absolute time is in nanoseconds. */ 91 88 if (g_Info.denom == 1 && g_Info.numer == 1) 92 89 return mach_absolute_time(); 93 90 94 91 /* general case: multiply by factor to get nanoseconds. */ 95 if (g_rdFactor != 0.0) 96 return mach_absolute_time() * g_rdFactor; 92 if (g_Info.denom > 0 && g_Info.numer > 0) 93 { 94 /* 95 * We could use clock_gettime_nsec_np(CLOCK_UPTIME_RAW) but internally 96 * it might be calling mach_timebase_info() for each call. This is most 97 * likely faster since we avoid calling mach_timebase_info() here. 98 */ 99 uint64_t const cTicks = mach_absolute_time(); 100 return ASMMultU64ByU32DivByU32(cTicks, g_Info.numer, g_Info.denom); 101 } 97 102 98 103 /* worst case: fallback to gettimeofday(). */
Note:
See TracChangeset
for help on using the changeset viewer.