Where the atomics have compare-and-swap and pointer operations, the
threaded runner takes no lock and waits on no condition variable.
Every task is on a live list from its push until it is retired: any
thread links it at the head, only the checking thread unlinks it, and
find(), retrieve() and the lookups behind wake, cancel and reset walk
it from any thread inside a read epoch. A retired task is cleaned up
and freed once no finder can still hold it, at once when none is
inside, since finders read task->state.
Workers take ready tasks from two bounded MPMC rings: the plain one,
which only the one worker takes from, and the parallel one, which
every worker does; what overflows waits behind them in order. A task
with a 'when' to wait for goes to the timer keeper, whichever idle
worker holds the token, which sleeps until the earliest is due and
hands the token on before it runs anything. Main-thread tasks and
finished ones reach the checking thread through lock-free stacks.
Workers, task_queue_wait() and deinit's bounded wait for the workers
park on eventcounts. Each gather with work in flight and each pass's
end advance one counter that both read, so a handler still sees what
the frame loop wrote before a check, as the frame count a load waits
on, and has read it before the loop writes again.
The volatile and PS2 backends keep the locked runner, as does GCD.
task_queue.c now uses retro_eventcount.c, which the sample builds
compiling it with threads now link.
task_queue_parallel_test floods both rings past what they hold with
every worker held; task_queue_switch_test holds a waker in
retro_eventcount_notify() where the runner takes no lock.
The sample and test builds used full debug info. -g1 keeps what
sanitizer reports and backtraces need - function names, files and line
numbers - and drops the variable and type information nobody reads in
CI. Objects get about 30% smaller (rh265.o under ASan+UBSan: 5.1MB to
3.7MB), so the ccache caches hold more of each job's build and are
quicker to restore and save.
Samples compiled shared tree sources in place, so whichever sample ran
next linked those objects with the flags they were built with, as
unity_identity did with mic_handshake's ASan objects. Every sample that
builds a source from outside its directory now includes
sample_objdir.mk and maps those objects under its own obj/; its own
objects stay where they were. The rule for the mapped objects has a
slash in its target, so make 3.81 does not strip the directory.
tools/sample_objdir_check.py dry-runs every sample Makefile and fails
on an object written outside the sample; the Samples-Objdir-Check
workflow runs it.
Two of the interactive task_queue_wait sites, both around the movie
tasks, and both resolved by the same underlying discovery.
runloop.c waited for the ENTIRE task queue to drain before starting
a movie recording, under a FIXME that admitted it did not know why
the guard inside task_moviectl_record_handler was insufficient and
guessed at either enqueue timing or a wrong finder call. The guess
about the finder was right, and the mechanism is worth stating
plainly: retro_task_regular_gather() lifts every running task off
tasks_running into a local list, then puts each one BACK as it
processes it. Whether content_load_state_in_progress() - a
task_queue_find() - sees a pending load therefore depends on where
that load sits in the pass relative to the caller. It is not
reliably blind, which is worse than if it were: it answers correctly
most of the time and wrongly some of the time, which is exactly the
shape of an intermittent ordering bug.
content_load_state_in_progress() now reads a main-thread flag, set
when a load task is pushed and cleared when its callback has applied
the state, including on the push-refused path where no callback will
run. That is the same correction already made in
task_database_info.c for the same class of window. With the guard
working, the whole-queue wait in runloop.c is deleted rather than
kept - the record task defers itself correctly now. The finder it
replaced is removed.
command.c's PLAY_REPLAY_SLOT handler waited on the whole queue so
that the movie task's callback would have installed the replay
handle before the reply was formatted. The handler it waits for is
trivial and finishes on its first invocation, so the wait was
already only about letting one tick happen - but a NULL condition
means "until the queue is empty", so a network command blocked on
every unrelated scan or download in flight. It now waits on a
predicate for that task alone. Producing the reply from the movie
callback instead would remove the wait entirely, but that needs
deferred-reply support in the command layer and is left for that
work.
A new oracle (samples/tasks/ordering) drives the shipping queue and
pins the contract this rests on: that a finder called from inside a
handler disagrees with the truth on at least one invocation, that a
main-thread flag does not, and that a task guarded by the flag runs
after the task it waits on. Reinstating the finder-based guard
makes the ordering lane fail with the dependent task running first -
the bug the FIXME described, reproduced.
Writing it corrected my own diagnosis: I expected the finder to be
uniformly blind for the whole pass, and the first version of the
lane asserted that and failed. Position dependence is the accurate
property and is what the lane now pins, so a future change to the
gather's put-back behaviour trips it deliberately.
Verified: strict C89 gates on task_save.c, task_movie.c, command.c
and runloop.c; full Linux build links with HAVE_QT=1; three lanes
pass plain, under ASan+UBSan+LSan and under TSan; the save_state
oracle - which covers the translation unit whose predicate changed -
still passes, as do the dirwalk, playlist, playlist_manager,
overlay, scan, NAT and watchdog oracles.