mirror of
https://github.com/libretro/parallel-gx1.git
synced 2026-11-07 04:26:01 -10:00
Every std::mutex, lock_guard, unique_lock, scoped_lock, condition_variable, call_once and semaphore left in Source/Core is replaced by a lock-free design: - Input: the device list, control bindings, stick calibration and default device are published snapshots read under a quiesce; a rebind requested while another thread is rebinding is handed to that thread instead of waited for. - WiimoteReal: the pool thread owns the slots and runs commands from an MPSC queue; the active Wiimotes are atomic slots. - EXI/SI/IOS devices: socket and packet traffic goes through SPSC rings or MPSC handoffs owned by one thread; USB scanning publishes its device list, and libusb transfers drain through a CallGate. - Memory cards: the flush thread applies change records queued by the CPU thread. - Custom assets: loads are scheduled as a published batch with an atomic cursor, results come back over an MPSC stack, and busy assets are skipped and retried. - D3D state and GL program caches use insert-only atomic maps (Common/AtomicHashMap.h). - Logging appends with O_APPEND / FILE_APPEND_DATA; FatFs reports busy instead of waiting; per-socket WSAStartup/WSACleanup. Deleted as unused by the libretro core: the profiler, the FIFO recorder, the volume verifier, the touch InputOverrider and the GameCube adapter's libusb path.
30 lines
1.1 KiB
C++
30 lines
1.1 KiB
C++
// Copyright 2026 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <retro_atomic.h>
|
|
|
|
namespace Common
|
|
{
|
|
// Lets a callback be unregistered while other threads may be calling it, without a lock on
|
|
// the calling path. A caller passes the gate to enter; closing it shuts out new callers and
|
|
// returns once the ones already inside have left, so the owner can then free what the
|
|
// callback captured. A callback closing its own gate from inside does not wait on itself.
|
|
struct CallGate
|
|
{
|
|
retro_atomic_int_t calls{};
|
|
retro_atomic_int_t closed{};
|
|
};
|
|
|
|
// False when the gate is closed; the callback must not run then. Pair a true with CallGateExit.
|
|
bool CallGateEnter(CallGate* gate);
|
|
void CallGateExit(CallGate* gate);
|
|
void CallGateClose(CallGate* gate);
|
|
// Returns once the calls inside now have left, leaving the gate open: for when the caller
|
|
// has already unpublished what those calls might be using.
|
|
void CallGateDrain(CallGate* gate);
|
|
// Undoes one CallGateClose; the gate lets calls in again once every close is undone.
|
|
void CallGateReopen(CallGate* gate);
|
|
} // namespace Common
|