[+] Mach steady time

This commit is contained in:
Reece Wilson 2023-11-02 17:34:46 +00:00
parent df784c45b8
commit 5041b2f241

View File

@ -11,6 +11,30 @@
#if defined(AURORA_IS_POSIX_DERIVED)
#if defined(AURORA_IS_XNU_DERIVED)
#include <mach/mach_time.h>
AUKN_SYM unsigned long long _NTLikeQueryFrequency()
{
static unsigned long long uFrequency {};
static AuInitOnce gInitOnce;
gInitOnce.Call([]
{
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
uFrequency = (timebase.denom * 1'000'000'000.0) / timebase.numer;
});
return uFrequency;
}
AUKN_SYM unsigned long long _NTLikeQueryCounter()
{
return mach_continuous_time();
}
#define GIB__GetSteadyTimeNS
#endif
#include <sys/resource.h>
#elif defined(AURORA_IS_MODERNNT_DERIVED)
@ -206,6 +230,23 @@
}
// benchmarking: https://github.com/microsoft/STL/issues/2085
#define GIB__GetSteadyTimeNS
// ~3.0741 seconds
// using high_res_clock = std::chrono::high_resolution_clock;
// ~6.07 seconds
// holy fuck, we're keeping this
// ~2x improvement
#else
using steady_clock = std::chrono::steady_clock;
#endif
#if defined(GIB__GetSteadyTimeNS)
static AuUInt64 _GetSteadyTimeNS()
{
static const long long gFreq = _NTLikeQueryFrequency();
@ -240,18 +281,6 @@
return uWhole + uPart;
}
}
// ~3.0741 seconds
// using high_res_clock = std::chrono::high_resolution_clock;
// ~6.07 seconds
// holy fuck, we're keeping this
// ~2x improvement
#else
using steady_clock = std::chrono::steady_clock;
#endif
using sys_clock = std::chrono::system_clock; // more stds to remove
@ -292,7 +321,7 @@ namespace Aurora::Time
AUKN_SYM AuUInt64 SteadyClock()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_XNU_DERIVED)
return _NTLikeQueryCounter();
#else
return SteadyClockNS() / (1000000000ull / SteadyClockJiffies());
@ -301,7 +330,9 @@ namespace Aurora::Time
AUKN_SYM AuUInt64 SteadyClockMS()
{
#if defined(AURORA_IS_POSIX_DERIVED)
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_XNU_DERIVED)
return AuNSToMS<AuUInt64>(_GetSteadyTimeNS());
#elif defined(AURORA_IS_POSIX_DERIVED)
::timespec spec {};
if (::clock_gettime(CLOCK_MONOTONIC, &spec) == 0)
{
@ -311,8 +342,6 @@ namespace Aurora::Time
{
return 0;
}
#elif defined(AURORA_IS_MODERNNT_DERIVED)
return AuNSToMS<AuUInt64>(_GetSteadyTimeNS());
#else
return std::chrono::duration_cast<std::chrono::milliseconds>(steady_clock::now().time_since_epoch()).count();
#endif
@ -320,7 +349,9 @@ namespace Aurora::Time
AUKN_SYM AuUInt64 SteadyClockNS()
{
#if defined(AURORA_IS_POSIX_DERIVED)
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_XNU_DERIVED)
return _GetSteadyTimeNS();
#elif defined(AURORA_IS_POSIX_DERIVED)
::timespec spec {};
if (::clock_gettime(CLOCK_MONOTONIC, &spec) == 0)
{
@ -330,8 +361,6 @@ namespace Aurora::Time
{
return 0;
}
#elif defined(AURORA_IS_MODERNNT_DERIVED)
return _GetSteadyTimeNS();
#else
return std::chrono::duration_cast<std::chrono::nanoseconds>(steady_clock::now().time_since_epoch()).count();
#endif
@ -345,7 +374,7 @@ namespace Aurora::Time
return gFrequency;
}
#if defined(AURORA_COMPILER_MSVC)
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_XNU_DERIVED)
return gFrequency = _NTLikeQueryFrequency();
#elif defined(AURORA_IS_POSIX_DERIVED)
::timespec spec {};