HLE/dsp: use atomic Status fields and release ordering without &mut aliasing #483
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/483"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T01:23:05Z.
Problem
In
crates/victory-hle/src/modules/dsp.rs:Status:XDspActivatehands the title a*const Statuspointer (status.write(&*new.status)) that title audio/worker threads poll asynchronously.XDspSubmitCommandcreated exclusive references&mut *streamand&mut *stream.statuswhile title threads could concurrently read*status, causing Rust aliasing UB even withwrite_volatile.XDspSubmitCommandreadstatus.submittednon-atomically and wrotesubmitted/result/completedviawrite_volatile(which does not provide inter-thread memory ordering over the precedingwrite_bytes(command.output, 0, samples)and can lose or regress tickets under concurrent submissions).Fix
#[repr(C)] Statusfields toAtomicU32/AtomicI32with compile-time layout assertions (size_of::<Status>() == 16,align_of::<Status>() == 4).&*streaminXDspSubmitCommand, serialize ticket increments and status updates under a per-streamMutex<()>, and publishcompletedwithOrdering::Releaseafter zeroingcommand.outputand storingsubmitted/result.concurrent_submissions_and_polling_are_monotonic_and_atomic.Verification
cargo test -p victory-hle --locked dsp::tests: 2 passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-hle --all-targets --locked -- -D warnings: cleancargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic unit tests only, no game data.)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.