summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Timer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/Common/Timer.cpp')
-rw-r--r--Source/Core/Common/Timer.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/Source/Core/Common/Timer.cpp b/Source/Core/Common/Timer.cpp
index 025fddeba6..d1da786a52 100644
--- a/Source/Core/Common/Timer.cpp
+++ b/Source/Core/Common/Timer.cpp
@@ -25,10 +25,14 @@ u32 Timer::GetTimeMs()
{
#ifdef _WIN32
return timeGetTime();
-#else
+#elif defined __APPLE__
struct timeval t;
(void)gettimeofday(&t, nullptr);
return ((u32)(t.tv_sec * 1000 + t.tv_usec / 1000));
+#else
+ struct timespec t;
+ (void)clock_gettime(CLOCK_MONOTONIC, &t);
+ return ((u32)(t.tv_sec * 1000 + t.tv_nsec / 1000000));
#endif
}
@@ -48,10 +52,14 @@ u64 Timer::GetTimeUs()
static double freq = GetFreq();
QueryPerformanceCounter(&time);
return u64(double(time.QuadPart) * freq);
-#else
+#elif defined __APPLE__
struct timeval t;
(void)gettimeofday(&t, nullptr);
return ((u64)(t.tv_sec * 1000000 + t.tv_usec));
+#else
+ struct timespec t;
+ (void)clock_gettime(CLOCK_MONOTONIC, &t);
+ return ((u64)(t.tv_sec * 1000000 + t.tv_nsec / 1000));
#endif
}
@@ -205,10 +213,14 @@ std::string Timer::GetTimeFormatted()
struct timeb tp;
(void)::ftime(&tp);
return StringFromFormat("%s:%03i", tmp, tp.millitm);
-#else
+#elif defined __APPLE__
struct timeval t;
(void)gettimeofday(&t, nullptr);
return StringFromFormat("%s:%03d", tmp, (int)(t.tv_usec / 1000));
+#else
+ struct timespec t;
+ (void)clock_gettime(CLOCK_MONOTONIC, &t);
+ return StringFromFormat("%s:%03d", tmp, (int)(t.tv_nsec / 1000000));
#endif
}
@@ -219,9 +231,12 @@ double Timer::GetDoubleTime()
#ifdef _WIN32
struct timeb tp;
(void)::ftime(&tp);
-#else
+#elif defined __APPLE__
struct timeval t;
(void)gettimeofday(&t, nullptr);
+#else
+ struct timespec t;
+ (void)clock_gettime(CLOCK_MONOTONIC, &t);
#endif
// Get continuous timestamp
u64 TmpSeconds = Common::Timer::GetTimeSinceJan1970();
@@ -236,8 +251,10 @@ double Timer::GetDoubleTime()
u32 Seconds = (u32)TmpSeconds;
#ifdef _WIN32
double ms = tp.millitm / 1000.0 / 1000.0;
-#else
+#elif defined __APPLE__
double ms = t.tv_usec / 1000000.0;
+#else
+ double ms = t.tv_nsec / 1000000000.0;
#endif
double TmpTime = Seconds + ms;