XTaskQueue: a dispatch serves every port, not only manual ones #2616
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!2616
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2616"
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?
@F1reworks10 on GitHub · 2026-11-25 16:56 UTC · original
F1reworks10:xtaskqueue-dispatch-any-mode→main· +122 −14 · 1 files · 1 commits · openXTaskQueueDispatchreturnedfalseimmediately for thread-pool, serialized and immediate ports. It ran nothing and did not wait out its timeout.The GDK documentation for XTaskQueueDispatch says:
timeoutInMs: "The number of milliseconds to wait for work to arrive before returning false."The public reference implementation behaves the same way. In libHttpClient's
TaskQueue.cpp,TaskQueuePortImpl::Dispatchtakes one entry from the port's queue whatever the port's mode, and waits up to the timeout for one.On main this has two consequences:
Change (
crates/victory-hle/src/modules/xasync.rs)XTaskQueueDispatchtakes the first one on the calling thread whatever the mode.false, as the reference does.run_first). That turn runs the port's first callback unless a dispatch already took it, so each callback still runs exactly once.XTaskQueueTerminatenow also cancels thread-pool callbacks that are still waiting for a pool thread. This matches its documentation: "All callbacks for both ports will be invoked with their canceled parameter set to true". On main the pool ran them uncancelled.Tests
dispatch_runs_a_serialized_ports_callback_on_the_calling_thread: fails on main, because the dispatch returnsfalseimmediately.dispatch_waits_its_timeout_on_a_thread_pool_port: fails on main, because the dispatch returns at once instead of after 200 ms.thread_pool_callbacks_run_once_wherever_they_run: checks that no callback runs twice when dispatches and the pool compete for them.cargo test -p victory-hlepasses (149 tests). Clippy is clean with-D warnings, with and without--all-features. Tested on Windows 11 with an RTX 3060 Ti.🤖 Generated with Claude Code
What was wrong: XTaskQueueDispatch returned false at once for a thread-pool, serialized or immediate port, without running anything and without waiting out its timeout. The GDK documentation of the function says it "can be called for any dispatch mode", that "a call is always dispatched on the thread that calls XTaskQueueDispatch", and that the timeout is "the number of milliseconds to wait for work to arrive before returning false". The public reference (libHttpClient's TaskQueue.cpp) drains one entry of the port's queue whatever the port's mode. A title loop that dispatches a thread-pool port with a timeout spun instead of waiting, and a thread that helps a busy port by dispatching it never ran anything. What changed: every port but an immediate one queues its callbacks, and XTaskQueueDispatch takes the first on the calling thread whatever the mode; an immediate port never queues one, so a dispatch of it waits out its timeout, as in the reference. A thread-pool port gives the pool one turn per callback, which runs the port's first callback unless a dispatch took it, so each callback still runs exactly once. Callbacks of a thread-pool port still waiting for a pool thread are now among those XTaskQueueTerminate cancels, as its documentation says ("All callbacks for both ports will be invoked with their canceled parameter set to true"); before, the pool ran them uncanceled. Evidence: `dispatch_runs_a_serialized_ports_callback_on_the_calling_thread` and `dispatch_waits_its_timeout_on_a_thread_pool_port` fail on main (the dispatch returns false at once). `thread_pool_callbacks_run_once_wherever_ they_run` checks that a callback a dispatch took is not run by the pool as well. `cargo test -p victory-hle` passes; clippy (with and without --all-features) is clean. Co-Authored-By: Claude Opus 5.5 <[email protected]>@kotekompotek on GitHub · 2026-11-25 17:45 UTC · original
Reviewed: moving ThreadPool onto the per-port task list plus a pool 'turn' that pops the front keeps FIFO order while letting
XTaskQueueDispatchserve any mode (per the docs, dispatch works on any dispatch mode). Turns are 1:1 with submissions, so a dispatch that drained the queue leaves a turn that harmlessly finds it empty; the extra Arc raw-ptr round trip is reclaimed inrun_first. CI green.@Marvisak on GitHub · 2026-11-25 22:15 UTC · original
Automated triage for the maintainers.
This PR no longer merges cleanly into
main(f3578e3). The conflict is incrates/victory-hle/src/modules/xasync.rs. It will be reviewed once it is rebased onto currentmain.Generated by Claude Code
2db677657bto93e93a0e9e@DrDarkDK on GitHub · 2026-11-25 17:00 UTC · original · requested changes
This extends the shared-port cancellation bug from #403 to thread-pool ports. On the base, those callbacks go straight to
POOL. With this PR they enter the sharedPort::tasksdeque, whichXTaskQueueTerminatedrains in full. If queue A and composite queue B share a thread-pool port, terminating B can now invoke A’s queued callback withcanceled = true.Could we reuse #403’s approach of tracking which queue owns each callback and add a regression test for shared thread-pool ports? libHttpClient also limits cancellation to the terminating queue’s port context. Reference implementation
Static review only.
AI-assisted with Codex.
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.