Duckstation/src/common/timer.h

51 lines
1.4 KiB
C
Raw Permalink Normal View History

2024-09-01 12:08:31 +00:00
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: PolyForm-Strict-1.0.0
2020-01-10 03:31:12 +00:00
#pragma once
#include <cstdint>
namespace Common {
class Timer
{
public:
using Value = std::uint64_t;
2020-01-10 03:31:12 +00:00
Timer();
2022-07-11 09:45:31 +00:00
static double GetFrequency();
static Value GetCurrentValue();
2020-01-10 03:31:12 +00:00
static double ConvertValueToSeconds(Value value);
static double ConvertValueToMilliseconds(Value value);
static double ConvertValueToNanoseconds(Value value);
static Value ConvertSecondsToValue(double s);
static Value ConvertMillisecondsToValue(double s);
static Value ConvertNanosecondsToValue(double ns);
static void BusyWait(std::uint64_t ns);
static void HybridSleep(std::uint64_t ns, std::uint64_t min_sleep_time = UINT64_C(2000000));
static void NanoSleep(std::uint64_t ns);
2021-01-28 10:11:31 +00:00
static void SleepUntil(Value value, bool exact);
2020-01-10 03:31:12 +00:00
void Reset();
2022-07-11 09:45:31 +00:00
void ResetTo(Value value) { m_tvStartValue = value; }
Value GetStartValue() const { return m_tvStartValue; }
2020-01-10 03:31:12 +00:00
double GetTimeSeconds() const;
double GetTimeMilliseconds() const;
double GetTimeNanoseconds() const;
2022-07-11 09:45:31 +00:00
double GetTimeSecondsAndReset();
double GetTimeMillisecondsAndReset();
double GetTimeNanosecondsAndReset();
2023-09-12 13:43:00 +00:00
bool ResetIfSecondsPassed(double s);
bool ResetIfMillisecondsPassed(double s);
bool ResetIfNanosecondsPassed(double s);
2020-01-10 03:31:12 +00:00
private:
Value m_tvStartValue;
};
} // namespace Common