Files
parallel-gx1/Source/Core/Common/Timer.h
T
LibretroAdmin cb214d1034 Core, VideoCommon: drop std::this_thread waits
Waits that polled now block on an eventcount that the waited-on thread
notifies:

- Booting in dual core waits for the CPU thread to reach its run loop
  instead of polling every millisecond.
- AsyncShaderCompiler::WaitUntilCompletion wakes as each worker
  finishes an item instead of every 33 ms.

Timed sleeps go through Common::SleepUntil and SleepCurrentThreadUs,
built on retro_sleep_us: the CoreTiming throttle, PrecisionTimer, real
Wiimote report pacing, Bluetooth timed transfers, the Linux L2CAP
connect retry and the BBA read thread's idle wait.

FrameTiming::ThrottleFrame had no callers and is deleted.
2026-11-05 20:11:34 +01:00

72 lines
1.5 KiB
C++

// Copyright 2008 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "Common/CommonTypes.h"
namespace Common
{
class Timer
{
public:
static u64 NowUs();
static u64 NowMs();
void Start();
// Start(), then decrement start time by the offset.
// Effectively "resumes" a timer
void StartWithOffset(u64 offset);
void Stop();
u64 ElapsedMs() const;
// The rest of these functions probably belong somewhere else
static u64 GetLocalTimeSinceJan1970();
static void IncreaseResolution();
static void RestoreResolution();
private:
u64 m_start_ms{0};
u64 m_end_ms{0};
bool m_running{false};
};
// Sleeps until target, with the OS sleep's granularity; returns at once if it has passed.
void SleepUntil(TimePoint target);
class PrecisionTimer
{
public:
PrecisionTimer();
~PrecisionTimer();
PrecisionTimer(const PrecisionTimer&) = delete;
PrecisionTimer& operator=(const PrecisionTimer&) = delete;
void SleepUntil(Clock::time_point);
private:
#ifdef _WIN32
// Using void* to avoid including Windows.h in this header just for HANDLE.
void* m_timer_handle;
#endif
};
// Similar to std::chrono::steady_clock except this clock
// specifically does *not* count time while the system is suspended.
class SteadyAwakeClock
{
public:
using rep = s64;
using period = std::nano;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<SteadyAwakeClock>;
static constexpr bool is_steady = true;
static time_point now();
};
} // Namespace Common