Skip to content

lv2: keep one authoritative semaphore count - #88

Open
canersaka wants to merge 2 commits into
sp00nznet:ps3recompfrom
canersaka:fix/semaphore-single-count
Open

lv2: keep one authoritative semaphore count#88
canersaka wants to merge 2 commits into
sp00nznet:ps3recompfrom
canersaka:fix/semaphore-single-count

Conversation

@canersaka

Copy link
Copy Markdown
Contributor

The Win32 semaphore path kept the guest count twice: once in sys_semaphore_info::value and again in the kernel semaphore handle. wait and trywait consumed the kernel count and then decremented value separately, while post updated value before releasing the handle. Timeout and wake races could make those counts disagree, producing lost tokens, negative bookkeeping or a waiter sleeping while value was already positive. The overflow path also returned CELL_EINVAL instead of the lv2 CELL_EBUSY contract.

This makes value under value_lock the only count on both host paths. The Win32 handle becomes a wake channel only, parked waiters recheck value under the lock, and post wakes at most min(count, waiters). The second commit wires the existing sync_stress target into the test build with the small standalone shims it needs, so this behavior stays executable outside a generated title.

Verified: ps3recomp_runtime builds clean and CTest passes the sync_stress target, 1 of 1 tests. On the unmodified base the same semaphore-counting section reports ten failures; on this branch its post, trywait, timed-wait and overflow checks all pass.

Make the Win32 kernel semaphore a wake channel while value remains the only count. Wait and trywait consume value under the lock; post updates it first and wakes only parked waiters. This removes the grant-before-shadow-decrement window that could reject a valid post and drop its wake. Match the POSIX overflow result to CELL_EBUSY.
@canersaka
canersaka marked this pull request as ready for review July 25, 2026 05:57
sp00nznet added a commit that referenced this pull request Aug 15, 2026
Folds every foldable open PR onto master: the #90/#82/#81/#79/#78 integration chain (fast-forward) plus canersaka's six fix PRs (#83-#88) cherry-picked with authorship preserved. Build clean, ctest 1/1.
tsautier pushed a commit to tsautier/ps3recomp that referenced this pull request Aug 15, 2026
… ABI/lv2 batch)

CONTRIBUTORS.md gains canersaka's six-PR batch (sp00nznet#83-sp00nznet#88); README gets an
Unreleased changelog section covering everything folded via
integrate/fold-2026-08-14, attributed per fix.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant