diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-02-01 06:37:47 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-02-01 06:37:47 +0100 |
commit | 71f5aac8d639a2fd6f18ae313a9d8784711049f1 (patch) | |
tree | 1500a3fbe201fb7ebf974fc1a8ad958f48fcc89b /compat/timer.cpp | |
parent | d00258dfc626000c70767796ccd18fad7815a8d3 (diff) |
compat/timer: remove platform-dependent stuff from header
Diffstat (limited to 'compat/timer.cpp')
-rw-r--r-- | compat/timer.cpp | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/compat/timer.cpp b/compat/timer.cpp index a3d91af4..7fa62e9c 100644 --- a/compat/timer.cpp +++ b/compat/timer.cpp @@ -21,20 +21,6 @@ void Timer::start() gettime(&state); } -// common - -void Timer::gettime(timespec* state) -{ -#if defined(_WIN32) || defined(__MACH__) - otr_clock_gettime(state); -#elif defined CLOCK_MONOTONIC - const int res = clock_gettime(CLOCK_MONOTONIC, state); - assert(res == 0 && "must support CLOCK_MONOTONIC"); -#else -# error "timer query method not known" -#endif -} - // nanoseconds long long Timer::elapsed_nsecs() const @@ -75,15 +61,18 @@ double Timer::elapsed_seconds() const // platform-specific code starts here // -- -#if defined _WIN32 -LARGE_INTEGER Timer::otr_get_clock_frequency() +#if defined (_WIN32) +# include <windows.h> + +static LARGE_INTEGER otr_get_clock_frequency() { LARGE_INTEGER freq{}; - (void) QueryPerformanceFrequency(&freq); + const BOOL ret = QueryPerformanceFrequency(&freq); + assert(ret && "QueryPerformanceFrequency failed"); return freq; } -void Timer::otr_clock_gettime(timespec* ts) +static void otr_clock_gettime(timespec* ts) { static const LARGE_INTEGER freq = otr_get_clock_frequency(); @@ -101,14 +90,17 @@ void Timer::otr_clock_gettime(timespec* ts) } #elif defined __MACH__ -mach_timebase_info_data_t Timer::otr_get_mach_frequency() +# include <inttypes.h> +# include <mach/mach_time.h> + +static mach_timebase_info_data_t otr_get_mach_frequency() { mach_timebase_info_data_t timebase_info; (void) mach_timebase_info(&timebase_info); return timebase_info; } -void Timer::otr_clock_gettime(timespec* ts) +static void otr_clock_gettime(timespec* ts) { static const mach_timebase_info_data_t timebase_info = otr_get_mach_frequency(); uint64_t state, nsec; @@ -119,3 +111,17 @@ void Timer::otr_clock_gettime(timespec* ts) } #endif + +// common + +void Timer::gettime(timespec* state) +{ +#if defined(_WIN32) || defined(__MACH__) + otr_clock_gettime(state); +#elif defined CLOCK_MONOTONIC + const int res = clock_gettime(CLOCK_MONOTONIC, state); + assert(res == 0 && "must support CLOCK_MONOTONIC"); +#else +# error "timer query method not known" +#endif +} |