Skip to content

Commit

Permalink
monotonicCurrentTimeInSeconds should return seconds, not milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
pdehne committed Oct 20, 2013
1 parent fae7082 commit ef1e2f8
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions src/beast/beast/chrono/impl/RelativeTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,32 +267,51 @@ namespace detail {

double monotonicCurrentTimeInSeconds()
{
return (uint32) GetTickCount64();
return (uint32) GetTickCount64() / 1000.0;
}

#elif BEAST_MAC || BEAST_IOS

#include <time.h>
double monotonicCurrentTimeInSeconds()

static double timebaseRatio()
{
uint64 numerator, denominator;
struct TimebaseRatio
{
TimebaseRatio ()
{
uint64 numerator;
double denominator;

mach_timebase_info_data_t timebase;
(void) mach_timebase_info (&timebase);

if (timebase.numer % 1000000 == 0)
{
numerator = timebase.numer / 1000000;
denominator = timebase.denom * 1000.0;
}
else
{
numerator = timebase.numer;
denominator = timebase.denom * (uint64) 1000000 * 1000.0;
}

ratio = numerator / denominator;
}

double ratio;
};

mach_timebase_info_data_t timebase;
(void) mach_timebase_info (&timebase);
static TimebaseRatio timebaseRatio;

if (timebase.numer % 1000000 == 0)
{
numerator = timebase.numer / 1000000;
denominator = timebase.denom;
}
else
{
numerator = timebase.numer;
denominator = timebase.denom * (uint64) 1000000;
}
return timebaseRatio.ratio;

}

return (uint32) ((mach_absolute_time() * numerator) / denominator);
double monotonicCurrentTimeInSeconds()
{
return mach_absolute_time() * timebaseRatio();
}

#else
Expand All @@ -303,7 +322,7 @@ double monotonicCurrentTimeInSeconds()
{
timespec t;
clock_gettime (CLOCK_MONOTONIC, &t);
return t.tv_sec * 1000 + t.tv_nsec / 1000000;
return t.tv_sec + t.tv_nsec / 1000000000.0;
}

#endif
Expand Down

0 comments on commit ef1e2f8

Please sign in to comment.