Files
parallel-gx1/Source/Core/Common/Flag.h
T
LibretroAdmin 1e2dbf6616 Remove all sleeping and wall-clock pacing from the core
retro_run runs one video frame and the frontend paces it, so the core no
longer paces itself:

- The speed limiter is gone: CoreTiming::Throttle and its host-time
  targets, VI skip, the presenter's presentation-time wait,
  PrecisionTimer, PerformanceMetrics/PerformanceTracker, and the
  emulation speed, precision timing, rush/smooth presentation and VI
  skip settings and core options. The Dolphin IOS device reports 100%
  and ignores speed limits a guest asks for.
- Common/FrameClock.c (C89) counts retro_run calls. Background threads
  that acted every so many milliseconds wait for a number of frames
  instead: real-Wiimote pool upkeep, scanning, write tests and
  reconnect retries, USB scanning, the USB Gecko and GBA link
  listeners, the BBA read thread, memory card flushing and the WC24
  scheduler. Shutdown wakes every waiter.
- Waits that polled or timed out now block until signalled: dual-core
  boot, PauseAndLock in the GPU loop, CPU thread jobs, shader
  compilation progress, BlockingLoop and ParallelFor setup and
  teardown.
- Bluetooth passthrough submits transfers straight to libusb; the
  output worker and its timed sleep are deleted, HCI command timeouts
  count emulated time, and blocking firmware commands wait for the
  adapter's events.
- Real Wiimote reports go out when produced; delayed ones carry a
  frame number.
- Common::Flag sits on retro_atomic.
- Deleted: SleepCurrentThread, YieldCPU, Common::SleepUntil,
  Event::WaitFor, BlockingLoop::WaitYield, timer resolution changes,
  the play-time tracker, Host_YieldToUI, FrameTiming::ThrottleFrame
  leftovers and the never-used DO_WAIT_FOR_WIIMOTES mode.
2026-11-05 22:05:03 +01:00

45 lines
1.5 KiB
C++

// Copyright 2014 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Abstraction for a simple flag that can be toggled in a multithreaded way.
//
// Simple API:
// * Set(bool = true): sets the Flag
// * IsSet(): tests if the flag is set
// * Clear(): clears the flag (equivalent to Set(false)).
//
// More advanced features:
// * TestAndSet(bool = true): sets the flag to the given value. If a change was
// needed (the flag did not already have this value)
// the function returns true. Else, false.
// * TestAndClear(): alias for TestAndSet(false).
#pragma once
#include <retro_atomic.h>
namespace Common
{
class Flag final
{
public:
// Declared as explicit since we do not want "= true" to work on a flag
// object - it should be made explicit that a flag is *not* a normal
// variable.
explicit Flag(bool initial_value = false) { retro_atomic_int_init(&m_val, initial_value); }
void Set(bool val = true) { retro_atomic_exchange_int(&m_val, val); }
void Clear() { Set(false); }
bool IsSet() const { return retro_atomic_load_seq_cst_int(&m_val) != 0; }
bool TestAndSet(bool val = true) { return retro_atomic_cas_int(&m_val, !val, val); }
bool TestAndClear() { return TestAndSet(false); }
// For waits that take a running flag, such as frame_clock_wait_until.
const retro_atomic_int_t* Raw() const { return &m_val; }
private:
mutable retro_atomic_int_t m_val;
};
} // namespace Common