feat(libkernel): implement pthread spinlocks and relative condition wait #3689

Merged
MarcZX10 merged 2 commits from upstream-pr/3689 into main 2026-10-11 22:23:54 +00:00
MarcZX10 commented 2026-10-11 15:22:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T15:22:45Z.


What

Implement the POSIX pthread spinlock family and pthread_cond_reltimedwait_np in libkernel, carrying David's two commits from issue #3554 with his commit authorship preserved.

  • Spinlock initialization, destruction, lock, trylock, and unlock follow FreeBSD 11.4 libthr's owner checks and error results. Process-shared locks use process-local storage because guest code runs in one host process.
  • pthread_cond_reltimedwait_np forwards the relative timeout to scePthreadCondTimedwait and translates the SCE result to POSIX error numbers. The timeout unit/signature is inferred from shadPS4; console behavior remains unverified and is recorded in TechnicalDebt.
  • Tests cover lock ownership/errors, mutual exclusion across two threads, relative timeout and signal wakeup, and mutex ownership after each wait result.

Tested

  • Linux, GCC 12.2, Release: built libkernel, guest_pthread_spin_tests, and guest_cond_timedwait_tests successfully.
  • CTest guest_pthread_spin and guest_cond_timedwait passed 3 consecutive runs (6/6).
  • python3 tools/check_conventions.py --base upstream/main and git diff --check passed.
  • The source issue author reports Windows 11 / WinLibs GCC 15.2.0 focused tests; @blawesom independently reports Linux GCC 16.2.1 full-suite results on the source branch. Those reports are documented in #3554; this PR's local validation is the Linux/GCC 12.2 run above.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One 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 in TechnicalDebt
  • No notes, investigation .md files 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
  • AI-assisted: yes

Closes #3554.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820120633 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3689). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T15:22:45Z. --- ### What Implement the POSIX pthread spinlock family and `pthread_cond_reltimedwait_np` in libkernel, carrying David's two commits from [issue #3554](https://github.com/boykopovar/AnyPS5/issues/3554) with his commit authorship preserved. - Spinlock initialization, destruction, lock, trylock, and unlock follow FreeBSD 11.4 libthr's owner checks and error results. Process-shared locks use process-local storage because guest code runs in one host process. - `pthread_cond_reltimedwait_np` forwards the relative timeout to `scePthreadCondTimedwait` and translates the SCE result to POSIX error numbers. The timeout unit/signature is inferred from shadPS4; console behavior remains unverified and is recorded in TechnicalDebt. - Tests cover lock ownership/errors, mutual exclusion across two threads, relative timeout and signal wakeup, and mutex ownership after each wait result. ### Tested - Linux, GCC 12.2, Release: built `libkernel`, `guest_pthread_spin_tests`, and `guest_cond_timedwait_tests` successfully. - CTest `guest_pthread_spin` and `guest_cond_timedwait` passed 3 consecutive runs (6/6). - `python3 tools/check_conventions.py --base upstream/main` and `git diff --check` passed. - The source issue author reports Windows 11 / WinLibs GCC 15.2.0 focused tests; @blawesom independently reports Linux GCC 16.2.1 full-suite results on the source branch. Those reports are documented in #3554; this PR's local validation is the Linux/GCC 12.2 run above. ### Checklist - [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] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes Closes #3554.
github-actions[bot] commented 2026-10-11 15:23:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T15:23:21Z.


Progress report (df64fa9 → 774f218)

📈 System libraries: 85.96% (+0.02%, +6 implemented functions)

✅ 6 implemented
Library Name
libkernel pthread_cond_reltimedwait_np_nid_postfix
libkernel pthread_spin_destroy_nid_postfix
libkernel pthread_spin_init_nid_postfix
libkernel pthread_spin_lock_nid_postfix
libkernel pthread_spin_trylock_nid_postfix
libkernel pthread_spin_unlock_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110550501 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3689#issuecomment-6110550501). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T15:23:21Z. --- <!-- progress-report --> ### Progress report (df64fa9 → 774f218) 📈 **System libraries**: 85.96% (+0.02%, +6 implemented functions) <details> <summary>✅ 6 implemented</summary> | Library | Name | | - | - | | libkernel | `pthread_cond_reltimedwait_np_nid_postfix` | | libkernel | `pthread_spin_destroy_nid_postfix` | | libkernel | `pthread_spin_init_nid_postfix` | | libkernel | `pthread_spin_lock_nid_postfix` | | libkernel | `pthread_spin_trylock_nid_postfix` | | libkernel | `pthread_spin_unlock_nid_postfix` | </details>
adriadam10 commented 2026-10-11 21:56:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:56:55Z.


Rebased onto current main: the only conflict was the TechnicalDebt.md line adjacency (both lines kept). Rebuilt libkernel; guest_pthread_spin and guest_cond_timedwait pass on the rebased tree. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114244208 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3689#issuecomment-6114244208). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:56:55Z. --- Rebased onto current main: the only conflict was the `TechnicalDebt.md` line adjacency (both lines kept). Rebuilt libkernel; `guest_pthread_spin` and `guest_cond_timedwait` pass on the rebased tree. Merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3689
No description provided.