feat(xgameruntime): implement the remaining XTaskQueue functions #39

Manually merged
github merged 1 commit from gh-pr/39/head into gh-pr/39/base 2026-11-26 19:15:03 +00:00
Owner

@⁠CaseReed on GitHub · 2026-11-22 18:48 UTC · original
CaseReed:feat/xtaskqueue-rest → main · +1154 −144 · 10 files · 1 commits · merged 2026-11-22 20:50 UTC

What

Implements the six functions of #23, the whole issue: XTaskQueueCreateComposite, XTaskQueueGetPort, XTaskQueueRegisterMonitor, XTaskQueueUnregisterMonitor, XTaskQueueRegisterWaiter, XTaskQueueUnregisterWaiter. Behaviour follows the public MIT libHttpClient task queue (Source/Task/TaskQueue.cpp) and its unit tests (TaskQueueTests.cpp); signatures come from the public XTaskQueue.h and the GDK documentation. Nothing is measured on a console; every difference from the reference is in the debt fragment.

Design, in TaskQueue.cpp:

  • Ports are shared objects. A port holds the queued callbacks, each tagged with the queue it was submitted through; that tag keeps the queue alive. XTaskQueueGetPort returns the port; a composite holds two ports and keeps their source queues alive. Terminating a queue removes only its own callbacks, delayed callbacks and waiters from a shared port, and XTaskQueueTerminate(wait) waits only for that queue's work.
  • Monitors. Each port knows the queues attached to it and the role it plays for each. After a callback is queued, every monitor of every attached queue is called with that role, outside any internal lock and before an immediate port runs the callback. XTaskQueueUnregisterMonitor waits for calls of that monitor running on other threads.
  • Waiters use a thread-pool wait: a signal queues the callback once and the wait is armed again after it returns. Termination calls each waiter with nothing queued once with canceled = true; closing a queue unregisters its waiters without calling them.
  • A null, foreign or released port handle given to XTaskQueueCreateComposite returns E_GAMERUNTIME_INVALID_HANDLE (0x8924010C, from the public GDK error code list), checked against a registry of live ports without reading the handle.

Two changes to existing behaviour, both towards the reference:

  • A queue with callbacks still queued now stays alive after its last handle is closed, until they run or termination cancels them. Before, they were dropped.
  • XTaskQueueTerminate(queue, true, ...) from a callback submitted through that queue now stops with AbxUnsupported on every port kind. The debt already said so, but the check only covered thread-pool callbacks: from a manual-dispatched or immediate callback it deadlocked.

Stops (AbxUnsupported), each listed in the fragment: unregistering a monitor from inside its own callback (the reference waits forever), closing the queue handle given to a monitor, and a waiter handle signaled as an abandoned mutex (the reference ignores it and leaves a dead registration).

Tested

Windows 11, MSVC 19.38 (VS 2022), Ninja, Release, clean build directory, with #38 applied locally only to get MSVC to build (not part of this PR):

  • CTest: 65/65 passed (pipeline_probe skipped: no Khronos validation layer on this machine). Five new e2e scenarios: taskqueue_composite, taskqueue_monitor, taskqueue_monitor_reentry, taskqueue_waiter, taskqueue_terminate_reentry.
  • The taskqueue* and async* scenarios repeated 50 times: 500/500.
  • Fifteen mutations of the implementation (monitors only for the submitting queue, unregister not waiting, waiter not re-armed, terminate removing every queue's callbacks from a shared port, composite not holding its sources, registry check skipped, running-queue marker not kept outside the thread pool, ...): each fails at least one scenario. Two are caught by a crash of the test title rather than by an assertion.
  • python tools/check_conventions.py, python tools/debt_fold.py --check pass; tools/progress.py --module xgameruntime: 58 to 64 implemented.
  • TaskQueue.cpp, FakeTitle.cpp and FakeXGameRuntime.cpp compile with -Wall -Wextra and no warning on MinGW-w64 GCC 13.1, 15.2 and 16.2 (Compiler Explorer).

Not tested: no MinGW binary was run here, the Windows CI job is the check for it. The abandoned-mutex stop and the path where a signal cannot be queued on a live queue (the thread pool refusing work) have no test. Nothing was measured on a console.

Self-review: an independent pass over the diff found one data race (a composite published to a shared port from its constructor, before it could be referenced safely) and the terminate-from-callback deadlock above; both are fixed in this commit, the first with a stress block in taskqueue_composite (2000 composites created and closed over a port that receives work). That block guards against the race coming back; it does not prove the fix, since the race almost never shows on x64. Timing checks in the new scenarios were rewritten as event hand-offs where a slow runner could have caused a false failure.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • python tools/check_conventions.py passes (no comments in code, one declaration per export, Conventional Commit subjects)
  • Unimplemented paths stop (AbxNotImplemented / AbxUnsupported); silent stubs are listed under Silent stubs through a debt fragment
  • Known gaps added, changed or removed through docs/dev/debt/changes/<branch>.md
  • Generic behaviour, not specific to one title
  • No game files, keys, notes or logs added to the repository
  • Depends on: none (independent of #38)
  • Fixes: Fixes #23
  • Unblocks: none
  • Source of behaviour: public libHttpClient TaskQueue.cpp, TaskQueueTests.cpp, XTaskQueue.h (MIT); GDK XTaskQueue documentation and error code list
  • AI-assisted: yes

🤖 Generated with Claude Code

**@⁠CaseReed** on GitHub · 2026-11-22 18:48 UTC · [original](https://github.com/Dark3581/AnyBox/pull/39) `CaseReed:feat/xtaskqueue-rest` → `main` · +1154 −144 · 10 files · 1 commits · merged 2026-11-22 20:50 UTC ### What Implements the six functions of #23, the whole issue: `XTaskQueueCreateComposite`, `XTaskQueueGetPort`, `XTaskQueueRegisterMonitor`, `XTaskQueueUnregisterMonitor`, `XTaskQueueRegisterWaiter`, `XTaskQueueUnregisterWaiter`. Behaviour follows the public MIT libHttpClient task queue (`Source/Task/TaskQueue.cpp`) and its unit tests (`TaskQueueTests.cpp`); signatures come from the public `XTaskQueue.h` and the GDK documentation. Nothing is measured on a console; every difference from the reference is in the debt fragment. Design, in `TaskQueue.cpp`: - **Ports are shared objects.** A port holds the queued callbacks, each tagged with the queue it was submitted through; that tag keeps the queue alive. `XTaskQueueGetPort` returns the port; a composite holds two ports and keeps their source queues alive. Terminating a queue removes only its own callbacks, delayed callbacks and waiters from a shared port, and `XTaskQueueTerminate(wait)` waits only for that queue's work. - **Monitors.** Each port knows the queues attached to it and the role it plays for each. After a callback is queued, every monitor of every attached queue is called with that role, outside any internal lock and before an immediate port runs the callback. `XTaskQueueUnregisterMonitor` waits for calls of that monitor running on other threads. - **Waiters** use a thread-pool wait: a signal queues the callback once and the wait is armed again after it returns. Termination calls each waiter with nothing queued once with `canceled = true`; closing a queue unregisters its waiters without calling them. - A null, foreign or released port handle given to `XTaskQueueCreateComposite` returns `E_GAMERUNTIME_INVALID_HANDLE` (`0x8924010C`, from the public [GDK error code list](https://learn.microsoft.com/en-us/gaming/gdk/_content/gc/reference/errorcodes)), checked against a registry of live ports without reading the handle. Two changes to existing behaviour, both towards the reference: - A queue with callbacks still queued now stays alive after its last handle is closed, until they run or termination cancels them. Before, they were dropped. - `XTaskQueueTerminate(queue, true, ...)` from a callback submitted through that queue now stops with `AbxUnsupported` on every port kind. The debt already said so, but the check only covered thread-pool callbacks: from a manual-dispatched or immediate callback it deadlocked. Stops (`AbxUnsupported`), each listed in the fragment: unregistering a monitor from inside its own callback (the reference waits forever), closing the queue handle given to a monitor, and a waiter handle signaled as an abandoned mutex (the reference ignores it and leaves a dead registration). ### Tested Windows 11, MSVC 19.38 (VS 2022), Ninja, Release, clean build directory, with #38 applied locally only to get MSVC to build (not part of this PR): - CTest: 65/65 passed (`pipeline_probe` skipped: no Khronos validation layer on this machine). Five new e2e scenarios: `taskqueue_composite`, `taskqueue_monitor`, `taskqueue_monitor_reentry`, `taskqueue_waiter`, `taskqueue_terminate_reentry`. - The `taskqueue*` and `async*` scenarios repeated 50 times: 500/500. - Fifteen mutations of the implementation (monitors only for the submitting queue, unregister not waiting, waiter not re-armed, terminate removing every queue's callbacks from a shared port, composite not holding its sources, registry check skipped, running-queue marker not kept outside the thread pool, ...): each fails at least one scenario. Two are caught by a crash of the test title rather than by an assertion. - `python tools/check_conventions.py`, `python tools/debt_fold.py --check` pass; `tools/progress.py --module xgameruntime`: 58 to 64 implemented. - `TaskQueue.cpp`, `FakeTitle.cpp` and `FakeXGameRuntime.cpp` compile with `-Wall -Wextra` and no warning on MinGW-w64 GCC 13.1, 15.2 and 16.2 (Compiler Explorer). Not tested: no MinGW binary was run here, the Windows CI job is the check for it. The abandoned-mutex stop and the path where a signal cannot be queued on a live queue (the thread pool refusing work) have no test. Nothing was measured on a console. Self-review: an independent pass over the diff found one data race (a composite published to a shared port from its constructor, before it could be referenced safely) and the terminate-from-callback deadlock above; both are fixed in this commit, the first with a stress block in `taskqueue_composite` (2000 composites created and closed over a port that receives work). That block guards against the race coming back; it does not prove the fix, since the race almost never shows on x64. Timing checks in the new scenarios were rewritten as event hand-offs where a slow runner could have caused a false failure. ### Checklist <!-- Rules behind each item: CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] `python tools/check_conventions.py` passes (no comments in code, one declaration per export, Conventional Commit subjects) - [x] Unimplemented paths stop (`AbxNotImplemented` / `AbxUnsupported`); silent stubs are listed under Silent stubs through a debt fragment - [x] Known gaps added, changed or removed through `docs/dev/debt/changes/<branch>.md` - [x] Generic behaviour, not specific to one title - [x] No game files, keys, notes or logs added to the repository - [x] Depends on: none (independent of #38) - [x] Fixes: Fixes #23 - [x] Unblocks: none - [x] Source of behaviour: public libHttpClient `TaskQueue.cpp`, `TaskQueueTests.cpp`, `XTaskQueue.h` (MIT); GDK XTaskQueue documentation and error code list - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
XTaskQueueCreateComposite, XTaskQueueGetPort, XTaskQueueRegisterMonitor, XTaskQueueUnregisterMonitor, XTaskQueueRegisterWaiter and XTaskQueueUnregisterWaiter, following the public libHttpClient task queue and its tests. A port is now an object queues share: each queued callback keeps the queue it was submitted through alive, and terminating a queue cancels only its own work. Waiting termination from a callback of the same queue now stops on every port kind instead of deadlocking on manual and immediate ports.

Fixes #23

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:15:03 +00:00
github manually merged commit 8539a07602 into gh-pr/39/base 2026-11-26 19:15:03 +00:00
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-22 18:48 UTC · original

Progress report (9486199 → 8539a07)

📈 Libraries: 26.34% (+1.3393%, +6 implemented functions)

✅ 6 implemented
Library Name
xgameruntime XTaskQueueCreateComposite
xgameruntime XTaskQueueGetPort
xgameruntime XTaskQueueRegisterMonitor
xgameruntime XTaskQueueRegisterWaiter
xgameruntime XTaskQueueUnregisterMonitor
xgameruntime XTaskQueueUnregisterWaiter

Changed libraries

Library Before After Change
xgameruntime 58/391 (14.83%) 64/391 (16.37%) +1.53%
**@⁠github-actions[bot]** on GitHub · 2026-11-22 18:48 UTC · [original](https://github.com/Dark3581/AnyBox/pull/39#issuecomment-7083888279) <!-- progress-report --> ### Progress report (9486199 → 8539a07) 📈 **Libraries**: 26.34% (+1.3393%, +6 implemented functions) <details> <summary>✅ 6 implemented</summary> | Library | Name | | - | - | | xgameruntime | `XTaskQueueCreateComposite` | | xgameruntime | `XTaskQueueGetPort` | | xgameruntime | `XTaskQueueRegisterMonitor` | | xgameruntime | `XTaskQueueRegisterWaiter` | | xgameruntime | `XTaskQueueUnregisterMonitor` | | xgameruntime | `XTaskQueueUnregisterWaiter` | </details> #### Changed libraries | Library | Before | After | Change | | - | - | - | - | | xgameruntime | 58/391 (14.83%) | 64/391 (16.37%) | +1.53% |
Author
Owner

@⁠Dark3581 on GitHub · 2026-11-22 20:50 UTC · original · approved these changes

Reviewed — looks good

The port and composite model follows the reference closely and the tests cover the hard parts; merging.

What I ran

Head 8539a07, merged onto current main. Windows 10, MinGW (WinLibs GCC 15.2 UCRT), Ninja, Release, clean build directory.

Results

Check Result Note
MinGW full build pass no warning
CTest 66/66 the five new taskqueue_* scenarios included
e2e_taskqueue* and e2e_async* repeated 500/500 10 scenarios, 50 runs each
check_conventions.py ok
debt_fold.py --check ok
progress.py --module xgameruntime 64 implemented from 58
CI pass

Findings

Blocking

None.

Non-blocking

  • I read the waiter paths most closely: Disarm skipping WaitForThreadpoolWaitCallbacks from inside the wait callback, RunWaiter re-arming only while armed, and WaitSignaled holding the waiter through shared_from_this. They hold up; the abandoned-mutex stop is the right call while nothing measures what a console does.
  • #40 touches the same scenario lists in core/libs/tests/CMakeLists.txt and docs/dev/ARCHITECTURE.md; whichever lands second needs the small rebase you mentioned.

Not verified

MSVC (this machine's Windows SDK 22621 has no gameinput.lib, so I ran MSVC only for #38), and anything on a console.

Thanks — the mutation runs and the stress block for the composite race are exactly what a change to shared queue state needs.

**@⁠Dark3581** on GitHub · 2026-11-22 20:50 UTC · [original](https://github.com/Dark3581/AnyBox/pull/39#pullrequestreview-6014464267) · **approved these changes** # Reviewed — looks good The port and composite model follows the reference closely and the tests cover the hard parts; merging. ## What I ran Head `8539a07`, merged onto current `main`. Windows 10, MinGW (WinLibs GCC 15.2 UCRT), Ninja, Release, clean build directory. ## Results | Check | Result | Note | |---|---|---| | MinGW full build | pass | no warning | | CTest | 66/66 | the five new `taskqueue_*` scenarios included | | `e2e_taskqueue*` and `e2e_async*` repeated | 500/500 | 10 scenarios, 50 runs each | | `check_conventions.py` | ok | | | `debt_fold.py --check` | ok | | | `progress.py --module xgameruntime` | 64 implemented | from 58 | | CI | pass | | ## Findings ### Blocking None. ### Non-blocking - I read the waiter paths most closely: `Disarm` skipping `WaitForThreadpoolWaitCallbacks` from inside the wait callback, `RunWaiter` re-arming only while `armed`, and `WaitSignaled` holding the waiter through `shared_from_this`. They hold up; the abandoned-mutex stop is the right call while nothing measures what a console does. - #40 touches the same scenario lists in `core/libs/tests/CMakeLists.txt` and `docs/dev/ARCHITECTURE.md`; whichever lands second needs the small rebase you mentioned. ## Not verified MSVC (this machine's Windows SDK 22621 has no `gameinput.lib`, so I ran MSVC only for #38), and anything on a console. Thanks — the mutation runs and the stress block for the composite race are exactly what a change to shared queue state needs.
This discussion has been locked. Commenting is limited to contributors.
No description provided.