hle(posix): fix wait-all rollbacks, waitable timer rearms, and work cancellation #499
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/499"
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 LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T22:18:24Z.
What this changes
Closes #490
Refs #456
Fixes three Win32 synchronisation and callback-cancellation bugs in
crates/victory-hle/src/host_posix:Waitable::give_back&sync::wait_registered(host_posix.rs,host_posix/sync.rs,victory-platform):WaitForMultipleObjects(..., wait_all = 1)take (sincetry_takenever consumed them), preserving any concurrentResetEvent.EPOCHand wake concurrentWaitForMultipleObjectswaiters whenever a rolled-back auto-resetEvent,Semaphore, or freedMutexbecomes available again, while advancing the rolling-back waiter'sseenepoch when no external signal intervened so it sleeps cleanly instead of spinning.TimerObject/SetWaitableTimer/CancelWaitableTimer(host_posix/system.rs):std::thread::spawn+ unlockedgenerationchecks with a single lazy worker thread perTimerObjectsynchronised underMutex<TimerState> + Condvar, retiring cleanly onDrop(CloseHandle) and rejecting nulldueor negativeperiod_ms.event.reset(),event.set(), re-arm, and cancellation understateprevents a preempted worker from an older arm from signalling a re-armed or cancelled timer early.WaitForThreadpoolWorkCallbacks(host_posix/system.rs):cancel != 0(fCancelPendingCallbacks) toPoolObject::wait_idle(matchingWaitForThreadpoolTimerCallbacks).How it was tested
cargo test --target x86_64-apple-darwin -p victory-hle --lib(including new tests for wait-all rollback wakeups, manual-reset preservation, waitable timer re-arm/cancel/close, andWaitForThreadpoolWorkCallbacks(..., 1))cargo clippy --target x86_64-apple-darwin -p victory-platform --all-targets -- -D warningscargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtaskcargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warningscargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warningscargo xtask policy(399 files ok)Checklist
docs/native-host.mdVICTORY_*variable and documentedcc @Olima34
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T22:20:05Z.
Thanks @Sheffy007. This may explain a freeze we couldn't pin down. In about 1 in 3 traced world runs on the preview branch, the game froze for 30 s at the first world frames until the title's own watchdog fired, with no GPU error and no command buffer in flight. Samples during the freeze show 46–47 title threads in
WaitForSingleObject, 6 inSleepConditionVariableCS, and none in the host. It was timing-sensitive: much more frequent withVICTORY_TRACE_GPU_FAILS=1(5 of 14) than without it (0 of 9).A lost wake-up in a wait-all rollback, or a timer re-arm signalled early or late by a stale worker, fits that profile better than anything on the GPU side.
We'll add #499 to our next runs with the switch that made the freeze frequent, and post the freeze count with and without it here.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T01:32:58Z.
Review: APPROVED
Check report (helping the maintainer clear the queue):
CI:
checkandmacos-scriptsgreen on313c3fab.Read: the whole diff.
give_backno longer re-sets a manual-reset event (a concurrentResetEventis kept), says whether it restored anything, and a restore bumps the epoch and wakes other multi-waiters without waking the caller itself (no busy spin).ReleaseMutexsignals only when the mutex is actually free.dueor a negative period now fail withERROR_INVALID_PARAMETER, as on Windows.WaitForThreadpoolWorkCallbackshonours its cancel flag.Local check on current main (
226645f9) merged with #454, this PR and #507:victory-hletests pass on x86_64-apple-darwin, Windows clippy (-D warnings) clean,cargo xtask policyok.Game runs, from one of our test sessions (one windowed 300 s run each, Series S, preview
b3c1a1b0+ #459 + #513,VICTORY_TRACE_GPU_FAILS=1 VICTORY_PASSES_PER_BUFFER=1):No regression and no measurable gain. The freeze this may explain didn't happen in any of these runs, with or without it, so these runs can't confirm the fix.
Thanks @Sheffy007!