mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 13:35:54 +00:00
RelativeTime tidying
This commit is contained in:
@@ -265,22 +265,22 @@ namespace detail {
|
|||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
double monotonicCurrentTimeInSeconds()
|
static double monotonicCurrentTimeInSeconds()
|
||||||
{
|
{
|
||||||
return (uint32) GetTickCount64() / 1000.0;
|
return GetTickCount64() / 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif BEAST_MAC || BEAST_IOS
|
#elif BEAST_MAC || BEAST_IOS
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
static double timebaseRatio()
|
static double monotonicCurrentTimeInSeconds()
|
||||||
{
|
{
|
||||||
struct TimebaseRatio
|
struct StaticInitializer
|
||||||
{
|
{
|
||||||
TimebaseRatio ()
|
StaticInitializer ()
|
||||||
{
|
{
|
||||||
uint64 numerator;
|
double numerator;
|
||||||
double denominator;
|
double denominator;
|
||||||
|
|
||||||
mach_timebase_info_data_t timebase;
|
mach_timebase_info_data_t timebase;
|
||||||
@@ -288,13 +288,15 @@ static double timebaseRatio()
|
|||||||
|
|
||||||
if (timebase.numer % 1000000 == 0)
|
if (timebase.numer % 1000000 == 0)
|
||||||
{
|
{
|
||||||
numerator = timebase.numer / 1000000;
|
numerator = timebase.numer / 1000000.0;
|
||||||
denominator = timebase.denom * 1000.0;
|
denominator = timebase.denom * 1000.0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
numerator = timebase.numer;
|
numerator = timebase.numer;
|
||||||
denominator = timebase.denom * (uint64) 1000000 * 1000.0;
|
// VFALCO NOTE I don't understand this code
|
||||||
|
//denominator = timebase.denom * (uint64) 1000000 * 1000.0;
|
||||||
|
denominator = timebase.denom * 1000000000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ratio = numerator / denominator;
|
ratio = numerator / denominator;
|
||||||
@@ -303,22 +305,16 @@ static double timebaseRatio()
|
|||||||
double ratio;
|
double ratio;
|
||||||
};
|
};
|
||||||
|
|
||||||
static TimebaseRatio timebaseRatio;
|
static StaticInitializer const data;
|
||||||
|
|
||||||
return timebaseRatio.ratio;
|
return mach_absolute_time() * data.ratio;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
double monotonicCurrentTimeInSeconds()
|
|
||||||
{
|
|
||||||
return mach_absolute_time() * timebaseRatio();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
double monotonicCurrentTimeInSeconds()
|
static double monotonicCurrentTimeInSeconds()
|
||||||
{
|
{
|
||||||
timespec t;
|
timespec t;
|
||||||
clock_gettime (CLOCK_MONOTONIC, &t);
|
clock_gettime (CLOCK_MONOTONIC, &t);
|
||||||
@@ -327,32 +323,31 @@ double monotonicCurrentTimeInSeconds()
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Converts milliseconds to a RelativeTme
|
// Records and returns the time from process startup
|
||||||
static RelativeTime toRelativeTime (uint32 ms)
|
static double getStartupTime()
|
||||||
{
|
{
|
||||||
return RelativeTime (ms / 1000.0);
|
struct StaticInitializer
|
||||||
|
{
|
||||||
|
StaticInitializer ()
|
||||||
|
{
|
||||||
|
when = detail::monotonicCurrentTimeInSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Records and returns the time from process startup
|
double when;
|
||||||
static RelativeTime getStartupTime()
|
|
||||||
{
|
|
||||||
struct StartupTime
|
|
||||||
{
|
|
||||||
StartupTime ()
|
|
||||||
{ s = toRelativeTime (detail::monotonicCurrentTimeInSeconds()); }
|
|
||||||
RelativeTime s;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static StartupTime startupTime;
|
static StaticInitializer const data;
|
||||||
|
|
||||||
return startupTime.s;
|
return data.when;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to call getStartupTime as early as possible
|
// Used to call getStartupTime as early as possible
|
||||||
struct StartupTimeStaticInitializer
|
struct StartupTimeStaticInitializer
|
||||||
{
|
{
|
||||||
StartupTimeStaticInitializer ()
|
StartupTimeStaticInitializer ()
|
||||||
{ getStartupTime(); }
|
{
|
||||||
|
getStartupTime();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static StartupTimeStaticInitializer startupTimeStaticInitializer;
|
static StartupTimeStaticInitializer startupTimeStaticInitializer;
|
||||||
@@ -361,7 +356,8 @@ static StartupTimeStaticInitializer startupTimeStaticInitializer;
|
|||||||
|
|
||||||
RelativeTime RelativeTime::fromStartup ()
|
RelativeTime RelativeTime::fromStartup ()
|
||||||
{
|
{
|
||||||
return detail::toRelativeTime (detail::monotonicCurrentTimeInSeconds()) - detail::getStartupTime();
|
return RelativeTime (
|
||||||
|
detail::monotonicCurrentTimeInSeconds() - detail::getStartupTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user