mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-22 10:50:15 -10:00
retro_eventcount parks on an object both sides hold. Code written around a futex, WaitOnAddress or C++20's atomic wait parks on bare addresses instead: a thread sleeps while the 32-bit words at up to eight addresses still hold the values it saw, and whoever changes one wakes it by naming that address. retro_waitaddr_wait, retro_waitaddr_notify_one and retro_waitaddr_notify_all do that over retro_eventcount and retro_atomic, with no lock of their own. A waiter is a record out of a pool that only grows, published in the bucket of each address it names; a notifier claims the records that name its address with a compare-and-swap on the record's state and generation and wakes them through each record's own eventcount. notify_one wakes one thread that was waiting when it was called. A notify with nobody waiting in the address's bucket is one read-modify-write: 13 ns for a store and a notify here, no syscall. The sample covers the bound, several addresses, notify_one against notify_all, and tokens handed to sleeping takers by notify_one alone, where a lost wake hangs the test - which found one while this was written (a claim that landed before the waiter had prepared its eventcount). Run over the futex and the condition-variable backends and under ThreadSanitizer and ASan/UBSan. Not run on Windows.