2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-02-09 21:53:22 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <chrono>
|
2020-02-10 16:20:40 +01:00
|
|
|
#include <memory>
|
2020-02-09 21:53:22 +01:00
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
class WallClock {
|
|
|
|
public:
|
2022-01-30 18:36:56 +01:00
|
|
|
static constexpr u64 NS_RATIO = 1'000'000'000;
|
|
|
|
static constexpr u64 US_RATIO = 1'000'000;
|
|
|
|
static constexpr u64 MS_RATIO = 1'000;
|
|
|
|
|
2020-09-29 21:19:37 +02:00
|
|
|
virtual ~WallClock() = default;
|
|
|
|
|
2020-02-10 16:20:40 +01:00
|
|
|
/// Returns current wall time in nanoseconds
|
2020-08-14 15:38:45 +02:00
|
|
|
[[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0;
|
2020-02-10 16:20:40 +01:00
|
|
|
|
|
|
|
/// Returns current wall time in microseconds
|
2020-08-14 15:38:45 +02:00
|
|
|
[[nodiscard]] virtual std::chrono::microseconds GetTimeUS() = 0;
|
2020-02-10 16:20:40 +01:00
|
|
|
|
|
|
|
/// Returns current wall time in milliseconds
|
2020-08-14 15:38:45 +02:00
|
|
|
[[nodiscard]] virtual std::chrono::milliseconds GetTimeMS() = 0;
|
2020-02-10 16:20:40 +01:00
|
|
|
|
|
|
|
/// Returns current wall time in emulated clock cycles
|
2020-08-14 15:38:45 +02:00
|
|
|
[[nodiscard]] virtual u64 GetClockCycles() = 0;
|
2020-02-10 16:20:40 +01:00
|
|
|
|
|
|
|
/// Returns current wall time in emulated cpu cycles
|
2020-08-14 15:38:45 +02:00
|
|
|
[[nodiscard]] virtual u64 GetCPUCycles() = 0;
|
2020-02-09 21:53:22 +01:00
|
|
|
|
2020-02-25 17:28:55 +01:00
|
|
|
virtual void Pause(bool is_paused) = 0;
|
|
|
|
|
2020-02-09 21:53:22 +01:00
|
|
|
/// Tells if the wall clock, uses the host CPU's hardware clock
|
2020-08-14 15:38:45 +02:00
|
|
|
[[nodiscard]] bool IsNative() const {
|
2020-02-09 21:53:22 +01:00
|
|
|
return is_native;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2020-11-25 21:21:03 +01:00
|
|
|
explicit WallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_, bool is_native_)
|
|
|
|
: emulated_cpu_frequency{emulated_cpu_frequency_},
|
|
|
|
emulated_clock_frequency{emulated_clock_frequency_}, is_native{is_native_} {}
|
2020-02-09 21:53:22 +01:00
|
|
|
|
|
|
|
u64 emulated_cpu_frequency;
|
|
|
|
u64 emulated_clock_frequency;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool is_native;
|
|
|
|
};
|
|
|
|
|
2022-01-30 18:57:23 +01:00
|
|
|
[[nodiscard]] std::unique_ptr<WallClock> CreateBestMatchingClock(u64 emulated_cpu_frequency,
|
|
|
|
u64 emulated_clock_frequency);
|
2020-02-09 21:53:22 +01:00
|
|
|
|
2023-03-02 03:06:19 +01:00
|
|
|
[[nodiscard]] std::unique_ptr<WallClock> CreateStandardWallClock(u64 emulated_cpu_frequency,
|
|
|
|
u64 emulated_clock_frequency);
|
|
|
|
|
2020-02-09 21:53:22 +01:00
|
|
|
} // namespace Common
|