PS2SDK
PS2 Homebrew Libraries
kernel_util.c
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
11 #include <kernel.h>
12 #include <timer_alarm.h>
13 #include <kernel_util.h>
14 
15 #ifdef F_WaitSemaEx
16 static u64 WaitSemaEx_callback(s32 id, u64 scheduled_time, u64 actual_time, void *arg, void *pc_value)
17 {
18  (void)id;
19  (void)scheduled_time;
20  (void)actual_time;
21  (void)pc_value;
22  iReleaseWaitThread((s32)arg);
23  return 0;
24 }
25 
27 s32 WaitSemaEx(s32 semaid, int signal, u64 *timeout)
28 {
29  int ret;
30  int timerid;
31 
32  timerid = -1;
33 
34  // TODO: other values NYI
35  if (signal != 1)
36  {
37  return -100;
38  }
39 
40  if (timeout != NULL && *timeout == 0)
41  {
42  ret = PollSema(semaid);
43  if (ret < 0)
44  {
45  return ret;
46  }
47  return semaid;
48  }
49 
50  if (timeout != NULL)
51  {
52  timerid = SetTimerAlarm(USec2TimerBusClock(*timeout), &WaitSemaEx_callback, (void *)GetThreadId());
53  }
54 
55  ret = WaitSema(semaid);
56 
57  if (timerid >= 0)
58  {
59  ReleaseTimerAlarm(timerid);
60  }
61 
62  return ret;
63 }
64 #endif
kernel.h
kernel_util.h