[proxy](3/n) remove chrono dependency for windows (#718)
* [proxy](3/n) remove chrono dependency for windows * minor fixes
This commit is contained in:
committed by
GitHub
parent
2cc74eac10
commit
8c6474d05a
@@ -24,8 +24,6 @@
|
|||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# include <chrono>
|
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
class PALWindows : public PalTimerDefaultImpl<PALWindows>,
|
class PALWindows : public PalTimerDefaultImpl<PALWindows>,
|
||||||
@@ -230,10 +228,21 @@ namespace snmalloc
|
|||||||
|
|
||||||
static uint64_t internal_time_in_ms()
|
static uint64_t internal_time_in_ms()
|
||||||
{
|
{
|
||||||
return static_cast<uint64_t>(
|
// Performance counter is a high-precision monotonic clock.
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
static stl::Atomic<uint64_t> freq_cache = 0;
|
||||||
std::chrono::steady_clock::now().time_since_epoch())
|
constexpr uint64_t ms_per_second = 1000;
|
||||||
.count());
|
SNMALLOC_UNINITIALISED LARGE_INTEGER buf;
|
||||||
|
auto freq = freq_cache.load(stl::memory_order_relaxed);
|
||||||
|
if (SNMALLOC_UNLIKELY(freq == 0))
|
||||||
|
{
|
||||||
|
// On systems that run Windows XP or later, the function will always
|
||||||
|
// succeed and will thus never return zero.
|
||||||
|
::QueryPerformanceFrequency(&buf);
|
||||||
|
freq = static_cast<uint64_t>(buf.QuadPart);
|
||||||
|
freq_cache.store(freq, stl::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
::QueryPerformanceCounter(&buf);
|
||||||
|
return (static_cast<uint64_t>(buf.QuadPart) * ms_per_second) / freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef PLATFORM_HAS_WAITONADDRESS
|
# ifdef PLATFORM_HAS_WAITONADDRESS
|
||||||
|
|||||||
Reference in New Issue
Block a user