Use mach_absolute_time and mach_timebase as an alternative to clock_gettime(2) on macOS platforms, to support earlier versions of the OS.
Details
Diff Detail
- Repository
- rCRT Compiler Runtime
- Build Status
Buildable 15608 Build 15608: arc lint + arc unit
Event Timeline
Just one suggestion below.
Thanks, @nglevin!
lib/xray/xray_x86_64.cc | ||
---|---|---|
103–105 | You can turn this into an "assured once" initialisation by doing something like: static const mach_timebase_info_data_t TI = [] { mach_timebase_info_data_t LocalTI; mach_timebase_info(&LocalTI); return LocalTI; }(); This way you let the compiler do the ensuring that the object is initialised once, and only on the first time it's invoked, in a thread-safe manner. |
lib/xray/xray_x86_64.cc | ||
---|---|---|
109 | Why are we returning "current time" when the function is supposed to return "TSC frequency"? How is a current timestamp a frequency value? |
Transform mach_timebase_info_data_t into an "assured once" initialisation, per feedback.
Add Mac-specific fallback logic to readTSC, retrieve "getTSCFrequency" via sysctlbyname using the XNU specific name of "machdep.tsc.frequency".
lib/xray/xray_x86_64.cc | ||
---|---|---|
109 | That was supposed to be the fallback logic that I had discussed earlier with Dean. My fault for putting this in the wrong file, where here, I should be using sysctl directly instead of a clock_gettime()-like workaround. As was previously done in the *BSD code path. Corrected. |
lib/xray/xray_x86_64.cc | ||
---|---|---|
85 | Please follow the naming convention around this file -- local variables are TitleCased. Also, use a function-local static constexpr character array instead of a non-const pointer. static constexpr char SysCtlTSCName[] = "..."; |
Please follow the naming convention around this file -- local variables are TitleCased.
Also, use a function-local static constexpr character array instead of a non-const pointer.