From 557d8e2f244ea31db35d177580d4cc3141f6e8f8 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Sun, 24 Dec 2023 12:53:14 +0000 Subject: [PATCH] PS2 use WaitSemaEx for waiting for semaphore with timeout --- src/thread/ps2/SDL_syssem.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/thread/ps2/SDL_syssem.c b/src/thread/ps2/SDL_syssem.c index f71d81b9d..ad0ca28c9 100644 --- a/src/thread/ps2/SDL_syssem.c +++ b/src/thread/ps2/SDL_syssem.c @@ -26,7 +26,7 @@ #include #include -#include +#include #include "SDL_error.h" #include "SDL_thread.h" @@ -38,11 +38,6 @@ struct SDL_semaphore s32 semid; }; -static void usercb(struct timer_alarm_t *alarm, void *arg) -{ - iReleaseWaitThread((int)arg); -} - /* Create a semaphore */ SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) { @@ -85,8 +80,8 @@ void SDL_DestroySemaphore(SDL_sem *sem) int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) { int ret; - struct timer_alarm_t alarm; - InitializeTimerAlarm(&alarm); + u64 timeout_usec; + u64 *timeout_ptr; if (!sem) { return SDL_InvalidParamError("sem"); @@ -99,12 +94,14 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) return 0; } + timeout_ptr = NULL; + if (timeout != SDL_MUTEX_MAXWAIT) { - SetTimerAlarm(&alarm, MSec2TimerBusClock(timeout), &usercb, (void *)GetThreadId()); + timeout_usec = timeout * 1000; + timeout_ptr = &timeout_usec; } - ret = WaitSema(sem->semid); - StopTimerAlarm(&alarm); + ret = WaitSemaEx(sem->semid, 1, timeout_ptr); if (ret < 0) { return SDL_MUTEX_TIMEDOUT;