Skip to content

Use GetThreadId/WakeupThread/SleepThread instead of CreateSema/SignalSema/WaitSema#861

Draft
uyjulian wants to merge 1 commit into
ps2dev:masterfrom
uyjulian:use_wakeup_thread_instead_of_sema
Draft

Use GetThreadId/WakeupThread/SleepThread instead of CreateSema/SignalSema/WaitSema#861
uyjulian wants to merge 1 commit into
ps2dev:masterfrom
uyjulian:use_wakeup_thread_instead_of_sema

Conversation

@uyjulian

Copy link
Copy Markdown
Member

Will improve handling in borderline cases where semaphore limit is exhausted
Replaced in the following case:

  • initial_value=0
  • SignalSema was in callback
  • CreateSema/WaitSema was in same thread

…teSema/SignalSema/WaitSema

Will improve handling in borderline cases where semaphore limit is exhausted
Replaced in the cases where initial_value=0, SignalSema was in callback and CreateSema/WaitSema is in same thread
@uyjulian uyjulian changed the title improvement: Use GetThreadId/WakeupThread/SleepThread instead of CreateSema/SignalSema/WaitSema Use GetThreadId/WakeupThread/SleepThread instead of CreateSema/SignalSema/WaitSema May 30, 2026
@uyjulian uyjulian marked this pull request as draft May 31, 2026 06:19
@sp193

sp193 commented Jun 7, 2026

Copy link
Copy Markdown
Member

I feel that you're just switching out who will actually get to use the semaphores. The libraries won't use a lot of semaphores, so shouldn't we be addressing the source of the 200 or something semaphores getting used?

It's subjective and probably down to preferences. I used to suggest that we don't deviate from how Sony designed the SDK. Any bugs that appear because of edge cases, would be caused by us and end up being for us to solve. However, what you're doing does seem more efficient and it's an interesting improvement over Sony's original design.

One area to note may be how iWakeupThread() works. The syscall is bugged in all EE kernels, whereby it cannot wakeup a thread that is presently in RUN state, despite the documented behaviour. So there's an official patch (which we also have) that will schedule a wakeup via WakeupThread(), via a thread that runs at the highest priority. In terms of efficiency, it's a longer path... but it may not mean anything. Does this matter for the accuracy of nanosleep()? If not, then this is more of a FYI.

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.

2 participants