[PR #600] [MERGED] kernel: Reimplement POSIX semaphores using std::counting_semaphore. #1660

Closed
opened 2026-02-27 21:13:27 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/600
Author: @squidbus
Created: 8/26/2024
Status: Merged
Merged: 8/28/2024
Merged by: @raphaelthegreat

Base: mainHead: posix-sem


📝 Commits (1)

  • 8ac7345 kernel: Reimplement POSIX semaphores using std::counting_semaphore.

📊 Changes

3 files changed (+77 additions, -67 deletions)

View changed files

📝 CMakeLists.txt (+0 -4)
📝 src/core/libraries/kernel/thread_management.cpp (+70 -63)
📝 src/core/libraries/kernel/thread_management.h (+7 -0)

📄 Description

Reimplements POSIX semaphores using std::counting_semaphore as a more cross-platform solution. Each function does error checking as defined by the POSIX spec.

For Windows this reduces reliance on winpthreads, and for macOS this fixes POSIX semaphores as apparently sem_init, sem_destroy, and sem_getvalue are not only marked as deprecated but also not implemented; only named POSIX semaphores are implemented.

One caveat is that std::counting_semaphore does not provide an equivalent for sem_getvalue. Instead we keep an atomic counter alongside the semaphore to track its value based on successful waits and posts.

Tested this on the Persona Dancing games and it resolves the issue I was having on macOS where the games would crash on launch. The invalid semaphores make the games' job threads think there is work to do as they do not properly check for errors, resulting in a jump to a null pointer.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/600 **Author:** [@squidbus](https://github.com/squidbus) **Created:** 8/26/2024 **Status:** ✅ Merged **Merged:** 8/28/2024 **Merged by:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Base:** `main` ← **Head:** `posix-sem` --- ### 📝 Commits (1) - [`8ac7345`](https://github.com/shadps4-emu/shadPS4/commit/8ac73451f115ba9fa523ddade294d8666e7d08da) kernel: Reimplement POSIX semaphores using std::counting_semaphore. ### 📊 Changes **3 files changed** (+77 additions, -67 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+0 -4) 📝 `src/core/libraries/kernel/thread_management.cpp` (+70 -63) 📝 `src/core/libraries/kernel/thread_management.h` (+7 -0) </details> ### 📄 Description Reimplements POSIX semaphores using `std::counting_semaphore` as a more cross-platform solution. Each function does error checking as defined by the POSIX spec. For Windows this reduces reliance on winpthreads, and for macOS this fixes POSIX semaphores as apparently `sem_init`, `sem_destroy`, and `sem_getvalue` are not only marked as deprecated but also not implemented; only named POSIX semaphores are implemented. One caveat is that `std::counting_semaphore` does not provide an equivalent for `sem_getvalue`. Instead we keep an atomic counter alongside the semaphore to track its value based on successful waits and posts. Tested this on the Persona Dancing games and it resolves the issue I was having on macOS where the games would crash on launch. The invalid semaphores make the games' job threads think there is work to do as they do not properly check for errors, resulting in a jump to a null pointer. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:13:27 +03:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
starred/shadPS4#1660
No description provided.