feat(libSceNKWebKit): implement WTF callOnMainThread and callOnMainRunLoop, with their AndWait forms #19363
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19363"
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 boykopovar/AnyPS5. Originally posted by B-Howell on 2026-11-13T06:21:14Z.
What
Implements four existing throwing
libSceNKWebKitstubs:WTF::callOnMainThread,WTF::callOnMainRunLoop,WTF::callOnMainThreadAndWaitandWTF::callOnMainRunLoopAndWait.They follow the pinned MainThread.cpp with
USE(WEB_THREAD)off, where both forms callRunLoop::main().dispatch(WTFMove(function)). The pinned WKRunLoop.cpp shows thatWKRunLoopCallOnMainThreadandWKRunLoopRunMainuse that same main run loop. So these four reuse the queue that already exists insrc/RunLoop.cppand theisMainThread/isMainRunLoopthat already exist insrc/WtfMainThread.cpp, instead of adding a second queue.The call takes ownership of the
WTF::Functioncallable and sets the caller'sFunctionto null, asWTFMovedoes. The callable runs on the main loop and is then destroyed through its deleting destructor. If the call throws, it is still destroyed.On the main thread the
AndWaitforms run the callable inline and leave it owned by the caller, as upstream'sfunction()does. From any other thread they queue it and block on a host semaphore until it has run. The order is call, then signal, then destroy, as in upstream.The ABI follows the pinned Function.h:
Functionis onestd::unique_ptr<Impl>(8 bytes), andCallableWrapperBasehas the Itanium vtable[D1, D0, call]. Both are pinned withstatic_assertinsrc/WtfFunctionAbi.hpp.A null or empty
Functionthrowsstd::invalid_argument, where upstream would call through a null pointer.The debt entry is added, and the four implemented rows are removed from the inventory table.
The wait uses a host-internal
std::promisethat nothing exports, so this does not overlap #14922 (WTF::BinarySemaphore).tools/progress.py --compareagainst main: +5 implemented functions (libSceNKWebKit 2986/11258 → 2991/11259). Four of them are the exports. The fifth is the internalAPS5_VABItrampoline that the run-loop callback type requires.Tested
All runs are on Linux (WSL2 Ubuntu 22.04, GCC 11, Release, Ninja).
New
nkwebkit_WtfCallOnMain. It checks dispatch to the main loop from the main thread and from a worker, that ownership is taken, that exactly one deleting destructor runs and no complete destructor runs, that theAndWaitforms run inline on the main thread with the caller keeping ownership, and that a worker'sAndWaitstays blocked until the main thread pumps the loop. It also checks that null or emptyFunctions throw and that a throwing callable is still destroyed.Red control: with the four exports as throwing stubs, the test fails with
Subprocess abortedandwhat(): _ZN3WTF16callOnMainThreadEONS_8FunctionIFvvEEE not implemented. Against main's originalint f()stubs, the test does not compile:conflicting declaration of C function.With this change:
nkwebkit_wtfcallonmain ... Passed 0.11 sec, 3/3 runs.ctest -R '^public_headers': 100% of 65 passed.After review 5887093870, on
a52ff1d6d1a: a worker'sAndWaitwith a throwing callable now catches the exception after the callable is destroyed, the loop keeps running, and an inline throw keeps the caller'sFunction;nkwebkit_wtfcallonmainpasses 3/3, and with the previousWtfMainThread.cppthe same test hangs (Timeout, 30 s).nkwebkit_baseandnkwebkit_mainthread: both pass.Not tested against a console module or a title.
On
3b9f0587e6a, an ordinary merge ofmainat82160bba912after #18538, conventions passed; doc-only conflict on the count line; count is main's stated 5949 minus this change's 4 removed stubs (5945). Main's code changes since the last merge are over 1,000 lines from this PR's hunks, so the earlier test results stand.0000b5409a2then adds the shared main-thread assumption to the debt entry (doc only).On
117faeb7cbc, an ordinary merge ofmainatf86ca3fa559after #19322 and #17764: Export.cpp and InventoryExports.hpp conflicted only on adjacent stub removals (ourscallOnMainRunLoopAndWait, main'scurrentTextBreakLocaleID), resolved by keeping both removals; count is main's stated 5940 minus this change's 4 removed stubs (5936). Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release:nkwebkit_wtfcallonmain3/3; conventions passed.On
2cf39cc0eb4, an ordinary merge ofmainatc612c4c9e89after #19460; doc-only union merge of the count line; count is main's stated 5939 minus this change's 4 removed stubs (5935). Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release:nkwebkit_wtfcallonmain3/3; conventions passed.On
2af4ff41a3e: merged main after #19603; count line removed. Ordinary merge ofmainat9b22c40f49a, conventions passed. The debt diff against main is now only this PR's entry and its 4 removed table rows. No code conflict and main changed none of this PR's other files, so not rebuilt.Checklist
Based on current
main; no other open PR implements the same functionsOne topic per PR; follow-ups go in a new PR
No comments in code except technical debt
Unimplemented paths throw (
NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt fileNo notes, investigation
.mdfiles or images added to the repository (attach them to this PR)New third-party code is a submodule built from source
Generic behaviour, not specific to one title
Depends on: none
Fixes: none
Unblocks: none
GPUs tested: n/a
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T06:32:15Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
c7b3bec7ba:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtfcallonmain_testsbuilt cleanly.nkwebkit_wtfcallonmain):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/include/WtfExports.hpp,core/libs/prx/libSceNKWebKit/src/WtfMainThread.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T23:46:56Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
aa10901913:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtfcallonmain_testsbuilt cleanly.nkwebkit_wtfcallonmain):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/include/WtfExports.hpp,core/libs/prx/libSceNKWebKit/src/WtfMainThread.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T04:33:35Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
335a692845:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtfcallonmain_testsbuilt cleanly.nkwebkit_wtfcallonmain):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/include/WtfExports.hpp,core/libs/prx/libSceNKWebKit/src/WtfMainThread.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me