gdk rt: XTaskQueueRegisterWaiter and UnregisterWaiter, two-phase queue termination (5 conformance scenarios) #270
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!270
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/270/head"
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?
@QuentinDanblon on GitHub · 2026-11-23 09:17 UTC · original
QuentinDanblon:pr/xtq-register-waiter→main· +351 −43 · 4 files · 2 commits · closed without mergingLibrary / area:
compat-common, GDK runtime task queues (src/gdk/rt.rs), conformance table (tests/gdk_xtaskqueue_conformance.rs)Exports changed (exports.txt rows): none. Two slots of the XAsync interface change: slot 20
XTaskQueueRegisterWaiterand slot 21XTaskQueueUnregisterWaiterwere theE_NOTIMPLstub.Source of the behaviour: libHttpClient
Source/Task/TaskQueue.cppatc5007fd9(MIT):TaskQueueImpl::RegisterWaitHandle,UnregisterWaitHandle,TerminateandOnTerminationCallback,TaskQueuePortImpl::RegisterWaitHandle,UnregisterWaitHandle,ProcessWaitCallback,DrainOneItemandCancelPendingEntries. The rules were followed and rewritten in Rust, no code copied. The libHttpClient line ofTHIRD_PARTY/CREDITSis extended. The termination order was measured on the PCxgameruntime.dll10.0.26100.9656.Rebased onto
de1e1da(r32j). Two commits, nothing of #266 left:8493396RegisterWaiter and UnregisterWaiter, the same change as before the rebase.cf2a326termination order, new, asked in review.What
8493396doesXTaskQueueRegisterWaiterregisters a Win32 thread-pool wait on the handle. Each time the handle is signalled, the callback is submitted once to the requested port. The wait is armed again only after that callback has run: an auto-reset event gives one callback perSetEvent, a manual-reset event left signalled gives a callback again after each one.E_POINTERfor a null callback or token,E_INVALIDARGfor a bad port, a null handle or a handle that is not a queue,E_ABORTon a terminated queue.XTaskQueueUnregisterWaiterremoves the registration, stops the wait and waits for a wait callback that is still queuing its entry. An entry already queued still runs, as in the reference.TaskQueueImpl::Terminate: the work port refuses new work at once, the completion port keeps accepting callbacks until the termination marker of the work port has run.verify_queue_terminationandverify_termination_of_composite_queueneed this.What
cf2a326doesMeasured on the PC runtime with a manual queue that holds one queued and one delayed callback on each port:
XTaskQueueTerminateE_ABORT, completionS_OKE_ABORT, completionE_ABORTE_ABORTon both portsOur runtime differed on two lines. Once the work port had drained, the completion port still returned
S_OKand ran that callback. And the delayed completion callback came before the one submitted after terminate.The cause was one count of callbacks in flight for both ports: the termination marker of the work port waited for the completion callbacks too. The count is now kept per port. The work port ends first and its delayed callbacks are queued, canceled, behind the callbacks already queued on it. When it holds no callback of the queue any more, the completion port refuses new callbacks and its delayed callbacks are queued the same way. The termination callback runs after the last of them.
New scenario
verify_termination_order_on_a_manual_queuechecks every line of the table.verify_termination_cancels_delayed_callbacks(already there) covers a delayed work callback on a thread-pool queue and on a manual queue.Both commits change the path of every queue termination, not only of queues with waiters.
Rows removed from
DIFFERS(5, 14 remain)verify_queue_termination,verify_register_with_auto_reset,verify_shared_port_queue_rundown_drops_its_wait_handles,verify_shared_port_queue_rundown_keeps_other_waiters,verify_termination_of_composite_queue. All by8493396.cf2a326removes none: I ranverify_termination_of_base_queue_keeps_composites,verify_terminate_waits_for_async_in_flightandverify_close_keeps_queued_callbackswithTOMBOX_XTQ_ALL=1and they still fail.Tests
On
cf2a326, RTX 5090 PC, Windows 11:cargo test -p compat-common --release --test gdk_xtaskqueue_conformance_real(same scenarios against the realxgameruntime.dll): 62 passed. The three scenarios ofNEWER_THAN_RUNTIMEreturn at once there, among them the twoverify_shared_port_queue_rundown_*.--test gdk_xtaskqueue_conformance: 5 runs, 62 passed each (the 14DIFFERSrows return at once).--lib: 4 runs. 3 runs: 149 passed. 1 run: 148 passed, 1 failed,os_host::tm_race_probe::tests::the_scan_finds_objects_by_their_vtableattm_race_probe.rs:317(new in r32j, not touched here). For comparison, 8--libruns on plainde1e1da: 6 passed, 2 failed iniat::tests::finds_the_bound_slot_of_an_import_of_this_binaryatiat.rs:81.pr_gate.py --base origin/main: 0 problems.68ba2a5: 10 conformance runs, the five scenarios alone 5 times each withTOMBOX_XTQ_ALL=1, 3--libruns, all passed.Not run green:
cargo test -p compat-common --releaseas a whole stops attests/gdk_fs_redirect.rs(new in r32j), which ends withSTATUS_STACK_OVERFLOWon this PC. Plainde1e1dadoes the same here, 2 runs of 2, so it does not come from this PR.Not covered, not claimed
No title was run. I have no game dump.
A wait that ends with a result other than
WAIT_OBJECT_0(an abandoned mutex) is not delivered and the wait is not armed again. The registration stays until it is unregistered or the queue ends. I did not check what the reference does there.The handle is not duplicated. The title must keep it open while it is registered. I did not check whether the console runtime duplicates it.
The race I fixed in review has no test of its own: a wait callback that fires during termination and cannot queue its entry now still gets its canceled callback (
closereads the pending flag after it has waited for the wait callbacks). I found it by reading, not by a failing run.The termination order is measured on manual ports only. On thread-pool and serialized ports the same code runs, and the existing termination scenarios pass, but the order itself is not asserted there.
Whether a completion callback dispatched after
XTaskQueueTerminateand before the work port has drained runs canceled on the PC runtime is not measured. Ours runs it canceled, as before.docs/BLOCKERS.mdline "25 libHttpClient-derived scenarios differ" is yours, I did not touch it. The count is 14.cargo test -p compat-commonpasses for what is listed aboveNo game or console files and no binaries included
No fake success; anything not possible is left
missingwith a note🤖 Generated with Claude Code
@omonkeyz on GitHub · 2026-11-23 09:41 UTC · original
#266 is now on main (
e3c62b7), so please rebase #270 onto main so that only the RegisterWaiter/UnregisterWaiter commit remains. Because it changes the task-queue path Trackmania uses at boot, it gets its own full-boot Trackmania check before it can go into a release.@omonkeyz on GitHub · 2026-11-23 09:46 UTC · original
One behaviour question to settle alongside the rebase. After a Begin whose operation fails, what does XAsyncGetStatus report for the call? And if Begin returns E_PENDING, is the call left incomplete? Could you add a conformance case for each? The termination order matters too: delayed callbacks should be cancelled before the termination callback runs, and a terminated queue should take no new work. Please cover those in the two-phase termination tests.
@QuentinDanblon on GitHub · 2026-11-23 10:28 UTC · original
Rebased onto
de1e1da(r32j). Nothing of #266 is left. The branch holds two commits:8493396, the RegisterWaiter/UnregisterWaiter commit, andcf2a326, new, for the termination order you asked about. The description above is rewritten for this state.All answers below were measured on the PC
xgameruntime.dll10.0.26100.9656 withgdk_xtaskqueue_conformance_real, then compared with ours.After a Begin whose op fails.
XAsyncBeginreturnsS_OK.XAsyncGetStatus(wait = false)returns the Begin failure as soon asXAsyncBeginhas returned, and so doesXAsyncGetResultSize. No work is queued. The completion callback is queued on the completion port and reads the same status. Ours already did this. Two things next to it differed: the PC runtime runs the Cleanup op after the completion callback when the call is completed during Begin (we ran it at once), andXAsyncScheduleon the failed call returns the failure (we returnedS_OKorE_INVALIDARG). That is XAsync and not task queues, so it is in its own PR with two scenarios: #271.Begin returning
E_PENDING. The PC runtime leaves the call incomplete: statusE_PENDING, no work, no completion callback, no Cleanup, and the call can still be scheduled and completed afterwards. Ours completed it. That defect came from my #266 (if hr < 0inbegin). You fixed it in r32j withverify_pending_begin_stays_pending; I dropped my copy of the fix and my scenario.Termination order. New scenario
verify_termination_order_on_a_manual_queue, table in the description. On the PC runtime the delayed callbacks of a port are canceled when that port is dispatched, after the callbacks already queued on it and before the termination callback. The work port refuses new callbacks fromXTaskQueueTerminateon. The completion port refuses them once the work port has drained, and both refuse after the termination callback. Ours differed on two points: the completion port still accepted a callback after the work port had drained, and it canceled its delayed callback ahead of a callback submitted after terminate.cf2a326fixes both by counting the callbacks in flight per port.cf2a326changes every queue termination again, so it belongs in the same full-boot Trackmania check as the first commit. I have no game dump and ran no title.Two things seen on plain
de1e1daon this PC (Windows 11 26300, RTX 5090), not caused by either PR:cargo test -p compat-common --release --test gdk_fs_redirectends withSTATUS_STACK_OVERFLOWincopy_move_and_replace_calls_follow_the_console_path_like_create_file, 2 runs of 2.cargo test -p compat-common --release --lib: 2 runs of 8 fail iniat::tests::finds_the_bound_slot_of_an_import_of_this_binary(iat.rs:81). On the #270 branch 1 run of 4 failed inos_host::tm_race_probe::tests::the_scan_finds_objects_by_their_vtable(tm_race_probe.rs:317).I did not look for the causes. Tell me if you want the full output.
@omonkeyz on GitHub · 2026-11-23 13:45 UTC · original
Applied locally on main with your authorship kept (cherry-picked,
d39a963); tests pass in a sandbox. It ships in the next release; this PR will be closed when that is pushed. Thanks.@QuentinDanblon on GitHub · 2026-11-23 18:08 UTC · original
Cross-check with #307 and with microsoft/libHttpClient (MIT), which ships a full XTaskQueue implementation: the two-phase termination table here matches the reference code, and the two points I had left unverified are confirmed there (waiter handle not duplicated; a wait result other than WAIT_OBJECT_0 is ignored and not rearmed). Details, line links and a proposed merge order with #307 are in the #307 thread.
@omonkeyz on GitHub · 2026-11-25 13:09 UTC · original
Applied on main in
d39a963(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.Pull request closed