summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2018-06-26 22:49:12 (GMT)
committerGitHub <noreply@github.com>2018-06-26 22:49:12 (GMT)
commit135263824f4f6d2f38b2d1c3d83fe981d5e50b19 (patch)
tree330f9631c2429c03d82c3afd430c4e30ab6ac56f /src
parent0a47706f8eccd58c28b3d921f781c7909e7461bd (diff)
downloadcoreclr-135263824f4f6d2f38b2d1c3d83fe981d5e50b19.zip
coreclr-135263824f4f6d2f38b2d1c3d83fe981d5e50b19.tar.gz
coreclr-135263824f4f6d2f38b2d1c3d83fe981d5e50b19.tar.bz2
mach_absolute_time as the primary clock source on macOS (corefx#30391) (#18505) (#18526)
macOS 10.12+ supports clock_gettime (HAVE_CLOCK_MONOTONIC is defined) However, mach_absolute_time has better resolution and should be used as the primary clock source.
Diffstat (limited to 'src')
-rw-r--r--src/pal/src/misc/time.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/pal/src/misc/time.cpp b/src/pal/src/misc/time.cpp
index d16fb58..b660cc0 100644
--- a/src/pal/src/misc/time.cpp
+++ b/src/pal/src/misc/time.cpp
@@ -202,7 +202,11 @@ QueryPerformanceCounter(
PERF_ENTRY(QueryPerformanceCounter);
ENTRY("QueryPerformanceCounter()\n");
do
-#if HAVE_CLOCK_MONOTONIC
+#if HAVE_MACH_ABSOLUTE_TIME
+ {
+ lpPerformanceCount->QuadPart = (LONGLONG)mach_absolute_time();
+ }
+#elif HAVE_CLOCK_MONOTONIC
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
@@ -214,10 +218,6 @@ QueryPerformanceCounter(
lpPerformanceCount->QuadPart =
(LONGLONG)ts.tv_sec * (LONGLONG)tccSecondsToNanoSeconds + (LONGLONG)ts.tv_nsec;
}
-#elif HAVE_MACH_ABSOLUTE_TIME
- {
- lpPerformanceCount->QuadPart = (LONGLONG)mach_absolute_time();
- }
#elif HAVE_GETHRTIME
{
lpPerformanceCount->QuadPart = (LONGLONG)gethrtime();
@@ -264,9 +264,7 @@ QueryPerformanceFrequency(
BOOL retval = TRUE;
PERF_ENTRY(QueryPerformanceFrequency);
ENTRY("QueryPerformanceFrequency()\n");
-#if HAVE_GETHRTIME || HAVE_READ_REAL_TIME || HAVE_CLOCK_MONOTONIC
- lpFrequency->QuadPart = (LONGLONG)tccSecondsToNanoSeconds;
-#elif HAVE_MACH_ABSOLUTE_TIME
+#if HAVE_MACH_ABSOLUTE_TIME
// use denom == 0 to indicate that s_TimebaseInfo is uninitialised.
if (s_TimebaseInfo.denom == 0)
{
@@ -277,9 +275,11 @@ QueryPerformanceFrequency(
{
lpFrequency->QuadPart = (LONGLONG)tccSecondsToNanoSeconds * ((LONGLONG)s_TimebaseInfo.denom / (LONGLONG)s_TimebaseInfo.numer);
}
+#elif HAVE_GETHRTIME || HAVE_READ_REAL_TIME || HAVE_CLOCK_MONOTONIC
+ lpFrequency->QuadPart = (LONGLONG)tccSecondsToNanoSeconds;
#else
lpFrequency->QuadPart = (LONGLONG)tccSecondsToMicroSeconds;
-#endif // HAVE_GETHRTIME || HAVE_READ_REAL_TIME || HAVE_CLOCK_MONOTONIC
+#endif // HAVE_MACH_ABSOLUTE_TIME
LOGEXIT("QueryPerformanceFrequency\n");
PERF_EXIT(QueryPerformanceFrequency);
return retval;
@@ -338,7 +338,17 @@ GetTickCount64()
{
ULONGLONG retval = 0;
-#if HAVE_CLOCK_MONOTONIC_COARSE || HAVE_CLOCK_MONOTONIC
+#if HAVE_MACH_ABSOLUTE_TIME
+ {
+ // use denom == 0 to indicate that s_TimebaseInfo is uninitialised.
+ if (s_TimebaseInfo.denom == 0)
+ {
+ ASSERT("s_TimebaseInfo is uninitialized.\n");
+ goto EXIT;
+ }
+ retval = (mach_absolute_time() * s_TimebaseInfo.numer / s_TimebaseInfo.denom) / tccMillieSecondsToNanoSeconds;
+ }
+#elif HAVE_CLOCK_MONOTONIC_COARSE || HAVE_CLOCK_MONOTONIC
{
clockid_t clockType =
#if HAVE_CLOCK_MONOTONIC_COARSE
@@ -354,16 +364,6 @@ GetTickCount64()
}
retval = (ts.tv_sec * tccSecondsToMillieSeconds)+(ts.tv_nsec / tccMillieSecondsToNanoSeconds);
}
-#elif HAVE_MACH_ABSOLUTE_TIME
- {
- // use denom == 0 to indicate that s_TimebaseInfo is uninitialised.
- if (s_TimebaseInfo.denom == 0)
- {
- ASSERT("s_TimebaseInfo is uninitialized.\n");
- goto EXIT;
- }
- retval = (mach_absolute_time() * s_TimebaseInfo.numer / s_TimebaseInfo.denom) / tccMillieSecondsToNanoSeconds;
- }
#elif HAVE_GETHRTIME
{
retval = (ULONGLONG)(gethrtime() / tccMillieSecondsToNanoSeconds);