Browse Source

PS2 use WaitSemaEx for waiting for semaphore with timeout

Julian Uy 1 year ago
parent
commit
557d8e2f24
1 changed files with 8 additions and 11 deletions
  1. 8 11
      src/thread/ps2/SDL_syssem.c

+ 8 - 11
src/thread/ps2/SDL_syssem.c

@@ -26,7 +26,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <timer_alarm.h>
+#include <kernel_util.h>
 
 #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;