move time fetch to time_get_impl

This commit is contained in:
Jupeyy 2018-03-12 16:12:06 +01:00
parent 081057d6b9
commit e0b8ecabe4
2 changed files with 30 additions and 38 deletions

View file

@ -944,14 +944,9 @@ void set_new_tick()
}
/* ----- time ----- */
int64 time_get()
int64 time_get_impl()
{
static int64 last = 0;
if(new_tick == 0)
return last;
if(new_tick != -1)
new_tick = 0;
{
#if defined(CONF_PLATFORM_MACOSX)
static int got_timebase = 0;
@ -986,6 +981,17 @@ int64 time_get()
}
}
int64 time_get()
{
static int64 last = 0;
if(new_tick == 0)
return last;
if(new_tick != -1)
new_tick = 0;
last = time_get_impl();
}
int64 time_freq()
{
#if defined(CONF_PLATFORM_MACOSX)
@ -1003,40 +1009,13 @@ int64 time_freq()
int64 time_get_microseconds()
{
static int64 last = 0;
{
#if defined(CONF_PLATFORM_MACOSX)
static int got_timebase = 0;
mach_timebase_info_data_t timebase;
uint64_t time;
uint64_t q;
uint64_t r;
if (!got_timebase)
{
mach_timebase_info(&timebase);
}
time = mach_absolute_time();
q = time / timebase.denom;
r = time % timebase.denom;
last = q * timebase.numer + r * timebase.numer / timebase.denom;
return last / (int64)1000;
return time_get_impl() / (int64)1000;
#elif defined(CONF_FAMILY_UNIX)
struct timespec spec;
clock_gettime(CLOCK_MONOTONIC, &spec);
last = (int64)spec.tv_sec*(int64)1000000 + (int64)spec.tv_nsec / 1000;
return last;
return time_get_impl();
#elif defined(CONF_FAMILY_WINDOWS)
int64 t;
QueryPerformanceCounter((PLARGE_INTEGER)&t);
int64 tf;
QueryPerformanceFrequency((PLARGE_INTEGER)&tf);
t = (t * (int64)1000000) / tf;
if(t < last) // for some reason, QPC can return values in the past
return last;
last = t;
return t;
return (time_get_impl() * (int64)1000000) / time_freq();
#else
#error not implemented
#endif

View file

@ -591,6 +591,18 @@ typedef unsigned long long uint64;
void set_new_tick();
/*
Function: time_get_impl
Fetches a sample from a high resolution timer.
Returns:
Current value of the timer.
Remarks:
To know how fast the timer is ticking, see <time_freq>.
*/
int64 time_get_impl();
/*
Function: time_get
Fetches a sample from a high resolution timer.
@ -600,6 +612,7 @@ void set_new_tick();
Remarks:
To know how fast the timer is ticking, see <time_freq>.
Uses <time_get_impl> to fetch the sample.
*/
int64 time_get();