TsundereStation/src
Lib bbde546dfd audio_stream: remove uncontended mutex from FIFO path
The libretro core is single-threaded by design: the SPU is driven by
TimingEvents from the same thread that runs retro_run_frame(), and
both AudioStream subclasses (LibretroAudioStream, NullAudioStream)
are libretro-only - no separate audio output thread exists. There
is no producer/consumer scenario that requires synchronization on
this FIFO; the mutex was always uncontended.

Even an uncontended std::mutex is not free: each lock/unlock pair
issues an atomic CAS plus the indirect call through libpthread.
With the SPU calling BeginWrite/EndWrite roughly 300 times per
frame (one per scheduled audio slice), that's ~600 atomic ops and
~15 us of pure overhead on every retro_run.

Drop the mutex, the std::unique_lock wrappers in Reconfigure() and
Shutdown(), the surrounding #include <mutex>, and the redundant
lock in NullAudioStream::FramesAvailable(). The header now matches
its actual constraints: a single-threaded FIFO.

If anyone ever reintroduces a threaded audio path, they will need
to add synchronization back. The comment in audio_stream.h
documents that requirement explicitly so the choice is not silently
forgotten.
2026-05-07 22:53:58 +02:00
..
common audio_stream: remove uncontended mutex from FIFO path 2026-05-07 22:53:58 +02:00
core libretro: cache lightgun state to avoid double input_state poll 2026-05-07 22:22:36 +02:00
libretro libretro: drop bounce-copy and dynamic_cast from audio upload path 2026-05-07 22:22:55 +02:00
CMakeLists.txt only #include <malloc.h> if it exists 2024-07-07 23:17:16 +00:00
config.h.cmake only #include <malloc.h> if it exists 2024-07-07 23:17:16 +00:00