Skip to content

[pull] master from libretro:master#977

Merged
pull[bot] merged 2 commits intoAlexandre1er:masterfrom
libretro:master
Apr 29, 2026
Merged

[pull] master from libretro:master#977
pull[bot] merged 2 commits intoAlexandre1er:masterfrom
libretro:master

Conversation

@pull
Copy link
Copy Markdown

@pull pull Bot commented Apr 29, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

A header-only API exposing acquire/release atomic loads, stores and
acq_rel fetch_add/fetch_sub for int and size_t, with a backend cascade
that picks the best primitive each toolchain offers:

  1. C11 <stdatomic.h>           - modern GCC/Clang/MSVC at -std=c11
  2. C++11 <atomic>              - C++ TUs at -std=c++11 or _MSVC_LANG
                                   >= 201103L
  3. GCC __atomic_*              - GCC 4.7+ / Clang 3.1+
                                   (Clang impersonates GCC 4.2 in
                                    __GNUC__, so the gate uses
                                    defined(__clang__) || version check
                                    to avoid falling through to __sync)
  4. MSVC Win32 Interlocked*     - VS2003+, OG Xbox, Xbox 360 XDK; on
                                   ARM/ARM64 the plain forms lack
                                   barriers (PostgreSQL hit this on
                                   Win11/ARM64 in 2025), so RMWs are
                                   bracketed with __dmb on those targets
  5. Apple OSAtomic*             - PPC / pre-10.7 fallback
  6. GCC __sync_*                - GCC 4.1-4.6
  7. volatile fallback           - last resort, single-core / x86 TSO
                                   only; emits a #warning unless
                                   suppressed

Capability flags exposed to callers:

  HAVE_RETRO_ATOMIC               always defined after include
  RETRO_ATOMIC_LOCK_FREE          defined iff a real backend selected
                                  (NOT for the volatile fallback)
  RETRO_ATOMIC_BACKEND_NAME       string literal, for diagnostics
  RETRO_ATOMIC_REQUIRE_LOCK_FREE  caller-side opt-in: setting this
                                  before include turns the volatile
                                  fallback into a #error

No active TU includes the header yet; it is the foundation for a future
SPSC fifo primitive and consolidates the hand-rolled atomic shims
currently scattered across coreaudio*.c/m, xaudio.c, mmdevice_common.c,
opensl.c, and gfx_thumbnail.c.

Sample: libretro-common/samples/atomic/retro_atomic_test/

  Single-threaded property checks of every macro plus a 1M-iteration
  SPSC stress test (when HAVE_THREADS) using rthreads sthread_create.
  Compile-time #error checks assert that every named real backend
  implies RETRO_ATOMIC_LOCK_FREE and that the volatile fallback never
  sets it.

CI: Linux-libretro-common-samples.yml

  - retro_atomic_test added to the native run allowlist (gcc, with
    the workflow's default ASan/UBSan)
  - new step: C++ smoke test compiled with both g++ and clang++ at
    -std=c++11/14/17 against the in-tree header
  - new step: retro_atomic_test built with clang -fsanitize=thread and
    run with TSAN_OPTIONS=halt_on_error=1; TSan instruments every
    atomic load/store and would flag a missing barrier in the SPSC
    stress that x86 TSO would otherwise hide
  - new job: retro-atomic-cross, matrix [aarch64, armv7], cross-compiles
    with gcc-aarch64-linux-gnu / gcc-arm-linux-gnueabihf, runs the
    binary under qemu-user-static, and grep-inspects the emitted asm
    for ldar/stlr/ldadd*_acq_rel (aarch64) or dmb/ldrex/strex (armv7);
    the inspect step exits 1 if no barrier mnemonics are found, which
    catches a silent regression to the volatile fallback

Verified locally:

  - x86_64 native (gcc, clang) + ASan/UBSan + TSan
  - AArch64 cross-compile + qemu, asm shows ldar/stlr/ldadd*_acq_rel
  - ARMv7 cross-compile + qemu, asm shows dmb/ldrex/strex
  - MIPSel cross-compile + qemu, asm shows ll/sc/sync
  - C++11/14/17/20 native (g++ and clang++)
  - C++98 (g++ and clang++) correctly falls through to GCC __atomic_*
  - All 9 forced-backend shape tests (C11, GCC __atomic_*, __sync_*,
    volatile, MSVC x86/x64/ARM64 mocked, Apple 32/64 mocked) plus
    forced C++11

Not verified on real hardware:

  - MSVC ARM64 (correct by construction from MS docs and PostgreSQL
    precedent; awaits Windows-on-ARM CI)
  - Real PowerPC SMP (Wii U, Xbox 360); reasoned from devkitPPC GCC
    and Microsoft's Xbox 360 lockless guide
  - __sync_* and Apple OSAtomic backends (dead code on every current
    target; selection requires GCC < 4.7 or pre-10.7 Apple)
@pull pull Bot locked and limited conversation to collaborators Apr 29, 2026
@pull pull Bot added the ⤵️ pull label Apr 29, 2026
@pull pull Bot merged commit 75ea1e4 into Alexandre1er:master Apr 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant