mirror of https://github.com/cemu-project/Cemu.git
Optimized timer code for macOS (#576)
This commit is contained in:
parent
fcab8f8f1a
commit
058d11b49b
|
@ -351,10 +351,9 @@ bool match_any_of(T1 value, T2 compareTo, Types&&... others)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] static std::chrono::steady_clock::time_point tick_cached() noexcept
|
[[nodiscard]] static std::chrono::steady_clock::time_point tick_cached() noexcept
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#if BOOST_OS_WINDOWS
|
||||||
// get current time
|
// get current time
|
||||||
static const long long _Freq = _Query_perf_frequency(); // doesn't change after system boot
|
static const long long _Freq = _Query_perf_frequency(); // doesn't change after system boot
|
||||||
const long long _Ctr = _Query_perf_counter();
|
const long long _Ctr = _Query_perf_counter();
|
||||||
|
@ -362,11 +361,14 @@ bool match_any_of(T1 value, T2 compareTo, Types&&... others)
|
||||||
const long long _Whole = (_Ctr / _Freq) * std::nano::den;
|
const long long _Whole = (_Ctr / _Freq) * std::nano::den;
|
||||||
const long long _Part = (_Ctr % _Freq) * std::nano::den / _Freq;
|
const long long _Part = (_Ctr % _Freq) * std::nano::den / _Freq;
|
||||||
return (std::chrono::steady_clock::time_point(std::chrono::nanoseconds(_Whole + _Part)));
|
return (std::chrono::steady_clock::time_point(std::chrono::nanoseconds(_Whole + _Part)));
|
||||||
#else
|
#elif BOOST_OS_LINUX
|
||||||
struct timespec tp;
|
struct timespec tp;
|
||||||
clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
|
clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
|
||||||
return std::chrono::steady_clock::time_point(
|
return std::chrono::steady_clock::time_point(
|
||||||
std::chrono::seconds(tp.tv_sec) + std::chrono::nanoseconds(tp.tv_nsec));
|
std::chrono::seconds(tp.tv_sec) + std::chrono::nanoseconds(tp.tv_nsec));
|
||||||
|
#elif BOOST_OS_MACOS
|
||||||
|
return std::chrono::steady_clock::time_point(
|
||||||
|
std::chrono::nanoseconds(clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#include <time.h>
|
#include <ctime>
|
||||||
|
|
||||||
uint32_t GetTickCount()
|
uint32_t GetTickCount()
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
#if BOOST_OS_LINUX
|
||||||
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
||||||
return (1000 * ts.tv_sec + ts.tv_nsec / 1000000);
|
return (1000 * ts.tv_sec + ts.tv_nsec / 1000000);
|
||||||
|
#elif BOOST_OS_MACOS
|
||||||
|
return clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW) / 1000000;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,11 +7,13 @@ HighResolutionTimer HighResolutionTimer::now()
|
||||||
LARGE_INTEGER pc;
|
LARGE_INTEGER pc;
|
||||||
QueryPerformanceCounter(&pc);
|
QueryPerformanceCounter(&pc);
|
||||||
return HighResolutionTimer(pc.QuadPart);
|
return HighResolutionTimer(pc.QuadPart);
|
||||||
#else
|
#elif BOOST_OS_LINUX
|
||||||
timespec pc;
|
timespec pc;
|
||||||
clock_gettime(CLOCK_MONOTONIC_RAW, &pc);
|
clock_gettime(CLOCK_MONOTONIC_RAW, &pc);
|
||||||
uint64 nsec = (uint64)pc.tv_sec * (uint64)1000000000 + (uint64)pc.tv_nsec;
|
uint64 nsec = (uint64)pc.tv_sec * (uint64)1000000000 + (uint64)pc.tv_nsec;
|
||||||
return HighResolutionTimer(nsec);
|
return HighResolutionTimer(nsec);
|
||||||
|
#elif BOOST_OS_MACOS
|
||||||
|
return HighResolutionTimer(clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +22,6 @@ HRTick HighResolutionTimer::getFrequency()
|
||||||
return m_freq;
|
return m_freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64 HighResolutionTimer::m_freq = []() -> uint64 {
|
uint64 HighResolutionTimer::m_freq = []() -> uint64 {
|
||||||
#if BOOST_OS_WINDOWS
|
#if BOOST_OS_WINDOWS
|
||||||
LARGE_INTEGER freq;
|
LARGE_INTEGER freq;
|
||||||
|
|
Loading…
Reference in New Issue