fix(libkernel): hand signalled semaphore tokens to queued waiters #5412
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5412"
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 EagleBearerYS on 2026-10-13T19:14:02Z.
What
sceKernelSignalSemaonly added to the count and woke the waiters, each of which then had to take the count itself. AsceKernelPollSemaorsceKernelWaitSemathat ran first took the tokens instead, so a thread that had queued for them could time out or keep waiting. #4899 fixes the same steal for event flags.sceKernelSignalSemanow hands its tokens to the queued waiters in the order they queued, passing over one that needs more than is left, and only what remains stays on the count. AsceKernelWaitSemaorsceKernelPollSemathat finds enough tokens still takes them without queueing.sceKernelCancelSemareports and cancels the queued waiters as before. shadPS4's semaphore works the same way.The second commit records that order in
docs/dev/debt/libkernel.md. The priority order thatSCE_KERNEL_SEMA_ATTR_TH_PRIOasks for is not modelled, as for event flags in #4899.This PR is independent of #4899: the code is in different files, only the approach is the same.
No title is claimed.
Tested
On GitHub's runners from my fork, on
mainat18c438b10(run):-DANYPS5_ENABLE_SPIRV_TOOLS=ON.On both:
guest_semaphore_handoff, 20 rounds: a thread waits on an empty semaphore, the main thread signals one token and polls right away. The poll must fail withEBUSY, and the waiting thread must get the token. Withmain'sSemaphore.cppthe test aborts; with the change it passes 20 runs in a row.core/libs/prx/libcandcore/libs/prx/libkernelpasses: 69 and 125 on Linux, 90 and 128 on Windows,guest_semaphoreincluded.tools/check_conventions.py --base origin/mainpasses for both commits.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:27:16Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed