HLE GameInput: serialize blocking enumeration with polling and publish callback token first #3302
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3302
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3302"
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?
@fuzeofficlal on GitHub · 2026-11-26 16:30 UTC · original
fuzeofficlal:fix/hle-gameinput-device-callback-sync→main· +545 −23 · 1 files · 1 commits · openSummary
Fixes two concurrency bugs in
IGameInput::RegisterDeviceCallbackincrates/victory-hle/src/modules/gameinput.rsunder concurrent background polling (Hub::poll):register_deviceinserted the newRegistrationintostate.callbacksand releasedhub.state()before runninghub.deliver(found)on the caller's thread. While blocking enumeration was in progress, the background poll thread could invoke the same callback concurrently and deliver a later disconnect transition before blocking enumeration had even delivered the initial connect snapshot (for example, delivering(device 1, DISCONNECTED)followed by the stale(device 1, CONNECTED)).*outpublication race:register_devicewrote*outonly after publishing the registration and async-enumeration events underhub.state()and releasing the lock, allowing a concurrent poll callback to run before*outwas written.Changes
*out = registration.tokenbefore acquiring and releasinghub.state()so the mutex release-acquire edge publishes the token before any poll callback can observe the registration.Registration::enumeratingwhile blocking enumeration delivers its initial snapshot on the caller's thread (cleared by anEnumeratingRAII guard). Whileenumeratingis set for a registration,State::pollandState::updatedefer transitions for that registration intostate.pendingin FIFO order without stalling unrelated registrations; once blocking enumeration completes, the next poll delivers the deferred transitions in chronological order (or drops them ifStopCallback/UnregisterCallbackremoved the registration).state.runninginHub::deliverwith aRunningRAII guard usingrposition+swap_removeand releasinghub.state()before callingreturned.notify_all(), and consolidateforget_lockedintounregister_callback's lock acquisition.UnregisterCallbackwaiting on blocking enumeration, and*outtoken visibility during async enumeration.Verification
blocking_enumeration_serializes_with_concurrent_poll_and_preserves_order(observed concurrent callback depth 2) andself_unregister_during_blocking_enumeration_cancels_remaining_and_deferred_events(observed concurrent disconnect delivery before self-unregister).cargo test -p victory-hle --locked --lib modules::gameinput::tests::(20 consecutive runs: 20/20 passed, 13/13 tests each)cargo test -p victory-hle --lockedandcargo test -p victory-hle --all-features --locked(all passed)cargo clippy --workspace --all-targets --locked -- -D warningsand--all-features(0 warnings)cargo test -p xtask --locked policy::tests::repository_passes_policy(passed)@Dukestar69 on GitHub · 2026-11-26 16:48 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64:
Registration::enumerating+ RAIIRunning/Enumeratingguards (and publishing the out-token before async callbacks run) cleanly preserves event ordering and unregister synchronization.cargo test -p victory-hle --lib modules::gameinput:: -- --test-threads=1: 14 passed, 0 failed (includingblocking_enumeration_serializes_with_concurrent_poll_and_preserves_order,concurrent_unregister_waits_for_blocking_enumeration_and_skips_remaining,out_token_is_visible_before_async_enumeration_callback_runs, andself_unregister_during_blocking_enumeration_cancels_remaining_and_deferred_events).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@cloph-dsp on GitHub · 2026-11-26 16:50 UTC · original
Independent Windows verification of PR #3302 (head
078bdca).CARGO_TARGET_DIR=D:\Victory-Contrib\target-3302,CARGO_BUILD_JOBS=2.cargo test --locked -p victory-hle --lib -- --exact modules::gameinput::tests::blocking_enumeration_serializes_with_concurrent_poll_and_preserves_order modules::gameinput::tests::self_unregister_during_blocking_enumeration_cancels_remaining_and_deferred_events modules::gameinput::tests::concurrent_unregister_waits_for_blocking_enumeration_and_skips_remaining modules::gameinput::tests::out_token_is_visible_before_async_enumeration_callback_runs4 passed; 0 failed; 152 filtered out, exit 0.git diff --check origin/main HEADclean.63bcca43(synthetic tests are added by this PR).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.