Repository navigation
xgameruntime_user: registered user change callbacks are kept and called through their task queue - #8422
xgameruntime_user: registered user change callbacks are kept and called through their task queue#8422tedin7 wants to merge 4 commits into
Conversation
|
At 1dc4af7, events raised after a callback unregisters itself still allocate notifications and fill its queue until the callback returns. On a manual completion queue, 4,096 such events require 4,096 extra dispatches. None of those dispatches calls the user callback. The unregister call marks the registration inactive. The running callback keeps the entry in Please include only active registrations when taking the snapshot under Manual-queue reproductionInsert this block just before {
struct Probe {
void* user;
Unregister remove;
XTaskQueueRegistrationToken token{};
int calls{};
} probe{user, at<Unregister>(user, 34)};
auto self_remove = [](void* ctx, XUserLocalId, uint32_t) {
auto& p = *static_cast<Probe*>(ctx);
++p.calls;
p.remove(p.user, p.token, false);
for (int i = 0; i < 4096; ++i)
rt::shims::xgameruntime_user_raise_change_for_test(0);
};
check(at<Register>(user, 33)(user, manual, &probe, self_remove, &probe.token) == S_OK, "register probe");
rt::shims::xgameruntime_user_raise_change_for_test(0);
XTaskQueueDispatch(manual, XTaskQueuePort::Completion, 0);
int extra = 0;
while (XTaskQueueDispatch(manual, XTaskQueuePort::Completion, 0)) ++extra;
std::printf("probe: callbacks=%d extra dispatches=%d\n", probe.calls, extra);
check(probe.calls == 1 && extra == 0, "no queue work for events raised after unregister");
}AI-assisted. |
tupacfan04
left a comment
There was a problem hiding this comment.
The core registration/dispatch logic looks sound (58 checks, CI queued), but the PR's new blocking-wait and queue-lifetime behavior is not exercised, and two messages still describe the old behavior.
- The blocking wait is never entered.
runtime/shims/xgameruntime_user.cpp:372-383:
registration->active = false;
if (wait && !inside_user_dispatch(registration.get()))
g_tokens_cv.wait(lock, [&] { return registration->running == 0; });
const bool done = registration->running == 0;Every wait = true call in the test avoids the wait: event_token is unregistered after its callback ran (running == 0); the queued cases are unregistered before dispatch; the nested case unregisters the outer token from inside the outer callback's dispatch (inside_user_dispatch true, so the wait is skipped, and the test only checks the immediate false). A lost wakeup, wrong predicate or missing notify would pass all 58 checks. Add a callback blocked on an event on a worker/ThreadPool-dispatched queue and a second thread calling unregister(token, true); assert it blocks until the callback is released, then returns true. Also check deferred completion of the nested token: a later unregister(nested.outer, true) should return true and a subsequent raise should be silent; a broken erase in UserNotification::run would currently pass.
-
The process queue and queue-handle lifetime are not tested. All deliveries use
Manualqueues, and the test keeps the handles open until every registration is gone, soXTaskQueueDuplicateHandleand theUserRegistrationdestructor'sXTaskQueueCloseHandleare never the last handle. The process-queue test only covers the disabled queue. Add a registration with the default ThreadPool process queue (or an explicit queue), close the caller's handle, raise and verify delivery, and/or checkXTaskQueueUninitializeafter all registrations are gone. -
Stale docs/test message.
docs/runtime_imports.md:377still says change callbacks are “only tracked as tokens,” and:383says “Unregistering a change callback is never pending, so it returns true for any token.” Both are false now: callbacks are delivered, and the code returnsfalsewhen a callback is running withwait = falseor when called from inside dispatch.runtime/test/xgameruntime_user_test.cpp:166-169still says “false would mean still pending, which never happens offline,” while the new nested test at:225expectsfalse. Update all three.
Synthetic only; no game files. AI-assisted (OpenCode).
|
Re-tested dcf6cff on Windows 11. The fix resolves my queue-growth finding. In the original manual-queue probe, the callback unregisters itself with I built AI-assisted. |
|
Tested For this change. #8673 could not be put in the same tree: it conflicts with this PR in Setup. Built with MSVC 14.52 (Visual Studio 18), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.1, Ninja RelWithDebInfo on Windows Server 2025 (no Vulkan driver there), then the same binaries run through
Under Wine the tree is test by test the same as Because the six were built together, there is no per-PR negative control in this run: a regression would have shown as a difference from |
|
Tested
AI-assisted (Claude Code). |
What
Deliver XUser change events to registered callbacks on their task queues and support unregistration.
Why
Slots 33–34 need to retain registrations and dispatch offline user changes when raised. This change was AI-assisted.
Tested
On p2,
/root/fast_test_exe.sh /root/c2-xuce xgameruntime_user_test: origin/main shim with a no-op test hook failed 2 of 47 checks; the initial change passed 47 of 47. Review fixes based on 1691100:/root/fast_test_exe.sh /root/c2-xuce2 xgameruntime_user_testpassed 58 of 58, including a disabled process queue, queued events unregistered with either wait setting, and nested dispatch unregistration. Windows executable under Wine; no GPU or driver used.@ItsNotRexed: an exe PR, as you asked.
Claim: #8344 (comment)