Changeset 15870 in vbox for trunk/src/VBox
- Timestamp:
- Jan 8, 2009 3:08:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/darwin/time-darwin.cpp
r8245 r15870 41 41 42 42 #include <iprt/time.h> 43 #include <iprt/assert.h> 43 44 #include "internal/time.h" 44 45 45 46 47 /******************************************************************************* 48 * Global Variables * 49 *******************************************************************************/ 50 static struct mach_timebase_info g_Info = { 0, 0 }; 51 static double g_rdFactor = 0.0; 52 static bool g_fFailedToGetTimeBaseInfo = false; 53 54 55 /** 56 * Perform lazy init (pray we're not racing anyone in a bad way). 57 */ 58 static void rtTimeDarwinLazyInit(void) 59 { 60 struct mach_timebase_info Info; 61 if (mach_timebase_info(&Info) == KERN_SUCCESS) 62 { 63 g_rdFactor = (double)Info.numer / (double)Info.denom; 64 g_Info = Info; 65 } 66 else 67 { 68 g_fFailedToGetTimeBaseInfo = true; 69 Assert(g_Info.denom == 0 && g_Info.numer == 0 && g_rdFactor == 0.0); 70 } 71 } 72 73 74 /** 75 * Internal worker. 76 * @returns Nanosecond timestamp. 77 */ 46 78 DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void) 47 79 { 48 static struct mach_timebase_info s_Info = { 0, 0 }; 49 static double s_rdFactor = 0.0; 50 51 /* get the factors the first time (pray we're not racing anyone) */ 52 if (s_Info.denom == 0) 53 { 54 static bool s_fFailedToGetTimeBaseInfo = false; 55 if (!s_fFailedToGetTimeBaseInfo) 56 { 57 struct mach_timebase_info Info; 58 if (mach_timebase_info(&Info) != KERN_SUCCESS) 59 { 60 s_rdFactor = (double)Info.numer / (double)Info.denom; 61 s_Info = Info; 62 } 63 else 64 { 65 s_Info.denom = s_Info.numer = 0; 66 s_fFailedToGetTimeBaseInfo = true; 67 } 68 } 69 } 80 /* Lazy init. */ 81 if (RT_UNLIKELY(g_Info.denom == 0 && !g_fFailedToGetTimeBaseInfo)) 82 rtTimeDarwinLazyInit(); 70 83 71 84 /* special case: absolute time is in nanoseconds */ 72 if ( s_Info.denom == 1 && s_Info.numer == 1)85 if (g_Info.denom == 1 && g_Info.numer == 1) 73 86 return mach_absolute_time(); 74 87 75 88 /* general case: multiply by factor to get nanoseconds. */ 76 if ( s_rdFactor != 0.0)77 return mach_absolute_time() * s_rdFactor;89 if (g_rdFactor != 0.0) 90 return mach_absolute_time() * g_rdFactor; 78 91 79 92 /* worst case: fallback to gettimeofday(). */
Note:
See TracChangeset
for help on using the changeset viewer.