diff options
Diffstat (limited to 'Source/Core/Common/Src/Timer.cpp')
| -rw-r--r-- | Source/Core/Common/Src/Timer.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Source/Core/Common/Src/Timer.cpp b/Source/Core/Common/Src/Timer.cpp index d4d9897006..6583202f99 100644 --- a/Source/Core/Common/Src/Timer.cpp +++ b/Source/Core/Common/Src/Timer.cpp @@ -21,6 +21,12 @@ #include <Windows.h> #include <mmsystem.h> #include <sys/timeb.h> +#else +#include <unistd.h> +#if !defined(_POSIX_TIMERS) || _POSIX_TIMERS == 0 +#define USE_GETTIMEOFDAY +#include <sys/time.h> +#endif #endif #include "Common.h" @@ -34,6 +40,10 @@ u32 Timer::GetTimeMs() { #ifdef _WIN32 return timeGetTime(); +#elif defined USE_GETTIMEOFDAY + struct timeval t; + (void)gettimeofday(&t, NULL); + return ((u32)(t.tv_sec * 1000 + t.tv_usec / 1000)); #else struct timespec t; (void)clock_gettime(CLOCK_MONOTONIC_RAW, &t); @@ -203,6 +213,10 @@ std::string Timer::GetTimeFormatted() struct timeb tp; (void)::ftime(&tp); sprintf(formattedTime, "%s:%03i", tmp, tp.millitm); +#elif defined USE_GETTIMEOFDAY + struct timeval t; + (void)gettimeofday(&t, NULL); + sprintf(formattedTime, "%s:%03d", tmp, (int)(t.tv_usec / 1000)); #else struct timespec t; (void)clock_gettime(CLOCK_REALTIME, &t); @@ -219,6 +233,9 @@ double Timer::GetDoubleTime() #ifdef _WIN32 struct timeb tp; (void)::ftime(&tp); +#elif defined USE_GETTIMEOFDAY + struct timeval t; + (void)gettimeofday(&t, NULL); #else struct timespec t; (void)clock_gettime(CLOCK_REALTIME, &t); @@ -236,6 +253,8 @@ double Timer::GetDoubleTime() u32 Seconds = (u32)TmpSeconds; #ifdef _WIN32 double ms = tp.millitm / 1000.0 / 1000.0; +#elif defined USE_GETTIMEOFDAY + double ms = t.tv_usec / 1000000.0; #else double ms = t.tv_nsec / 1000000000.0; #endif |
