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 | |
parent | d00258dfc626000c70767796ccd18fad7815a8d3 (diff) |
compat/timer: remove platform-dependent stuff from header
Diffstat (limited to 'compat')
-rw-r--r-- | compat/timer.cpp | 46 | ||||
-rw-r--r-- | compat/timer.hpp | 13 |
2 files changed, 26 insertions, 33 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 +} diff --git a/compat/timer.hpp b/compat/timer.hpp index a92d3f68..03b537ac 100644 --- a/compat/timer.hpp +++ b/compat/timer.hpp @@ -13,23 +13,10 @@ #include <ctime> -#if defined (_WIN32) -# include <windows.h> -#elif defined(__MACH__) -# include <inttypes.h> -# include <mach/mach_time.h> -#endif - class OTR_COMPAT_EXPORT Timer final { struct timespec state; long long conv_nsecs(const struct timespec& cur) const; - static void otr_clock_gettime(struct timespec* ts); -#ifdef _WIN32 - static LARGE_INTEGER otr_get_clock_frequency(); -#elif defined(__MACH__) - static mach_timebase_info_data_t otr_get_mach_frequency(); -#endif static void gettime(struct timespec* state); |