Decouple emulator wake pipe from window subsystem
The self-pipe trick (wake_fd) was previously coupled to the window backend: wake_fd was only
declared under VIRTIOINPUT || VIRTIOGPU, pipe creation required g_window.window_main_loop, and poll/drain/signal-wakeup handling shared the window guards.
When building without SDL2 (ENABLE_SDL=0), the Makefile disables VIRTIOGPU and VIRTIOINPUT while other background threads such as VIRTIOSND and signal handlers still need to unblock poll(-1) in the SMP scheduler. In addition, virtio-snd never notified wake_fd on TX worker completions, and unmasked helper threads spawned by virtio_snd_init() / PortAudio could handle SIGINT/SIGTERM after teardown closed the pipe.
Changes
- Decouple wake-pipe lifecycle: Make
wake_fd[2], pipe setup undervm->n_hart > 1(both ends non-blocking),signal_wake_fd,semu_close_wake_pipe(),semu_cleanup_backends(), andsemu_run()poll/drain paths unconditional while keepingg_windowcalls underVIRTIOINPUT || VIRTIOGPU. - Drain and exit ordering: Drain all queued wake bytes in
semu_run(), runemu_tick_peripherals()immediately, and break cleanly onemu->stopped || signal_received. - Plain teardown: Close
wake_fdwith plainclose()and reset fields to-1insemu_close_wake_pipe(), relying on callers running on the emulator thread or afterpthread_join(). - VirtIO-Sound wakeup & signal masking: Expose
virtio_snd_set_wake_fd(), write one wake byte from thevirtio-sndTX worker when completions orvirtio_snd_set_fail()raiseInterruptStatus, and blockSIGINT/SIGTERMaroundpthread_create(),Pa_Initialize(),Pa_OpenStream(), andPa_StartStream(). - Unit test & CI: Add
tests/test_vsnd_wake.c,PA_LDFLAGS/unit-testtargets inMakefile,.ci/test-unit.sh, Linux/macOS CI steps in.github/workflows/main.yml, and.gitignoreentries for test artifacts.
Summary by cubic
Decouples the emulator wake pipe from the window subsystem so VIRTIOSND and other async devices can wake the SMP scheduler's poll(-1) in headless or ENABLE_SDL=0 builds.
Previously the wake pipe was only created when a window backend was present (g_window.window_main_loop and VIRTIOINPUT/VIRTIOGPU), so builds without SDL2 had no way to unblock the emulator's idle wait from background threads.
- Creates the wake pipe whenever the SMP scheduler runs (
vm->n_hart > 1), marks both ends non-blocking, and drains all queued wake bytes before ticking peripherals. - Wires the
VIRTIOSNDTX worker to write a wake byte on completions and device-fail throughvirtio_snd_set_wake_fd(). - Blocks SIGINT/SIGTERM around helper-thread creation (window init, virtio-snd TX worker, PortAudio init/open/start) so spawned threads inherit the mask; signals stay unblocked only while the emulator or window loop runs, and are re-blocked before teardown.
- Keeps all
g_windowcalls underVIRTIOINPUT || VIRTIOGPU, with teardown throughsemu_close_wake_pipe()andsemu_cleanup_backends(). - Adds a
unit-testMakefile target with atest_vsnd_wakeharness, run in Linux and macOS CI.