sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
sleep.c
Go to the documentation of this file.
1
/*
2
# _____ ___ ____ ___ ____
3
# ____| | ____| | | |____|
4
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5
#-----------------------------------------------------------------------
6
# Copyright 2001-2005, 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
15
16
#include <
kernel.h
>
17
#include <
unistd.h
>
18
#include <stdint.h>
19
#include <errno.h>
20
#include <
time.h
>
21
#include <
timer_alarm.h
>
22
23
static
u64 nanosleep_wakeup_callback(s32 alarm_id, u64 scheduled_time, u64 actual_time,
void
*arg,
void
*pc_value)
24
{
25
(void)alarm_id;
26
(void)scheduled_time;
27
(void)actual_time;
28
(void)pc_value;
29
30
iSignalSema((s32)arg);
31
ExitHandler();
32
return
0;
33
}
34
35
int
nanosleep(
const
struct
timespec *req,
struct
timespec *rem)
36
{
37
u32 eie;
38
s32 sema_id;
39
s32 timer_alarm_id;
40
ee_sema_t sema;
41
42
eie = get_mips_cop_reg(0,
COP0_REG_Status
);
43
if
((eie & 0x10000) == 0)
44
{
45
errno =
ENOSYS
;
// Functionality not available
46
return
-1;
47
}
48
sema.max_count = 1;
49
sema.option = (u32)
"nanosleep"
;
50
sema.init_count = 0;
51
sema_id = CreateSema(&sema);
52
if
(sema_id < 0)
53
{
54
errno =
EAGAIN
;
// Resource temporarily unavailable
55
return
-1;
56
}
57
timer_alarm_id =
SetTimerAlarm
(Sec2TimerBusClock(req->tv_sec) + NSec2TimerBusClock(req->tv_nsec), nanosleep_wakeup_callback, (
void
*)sema_id);
58
if
(timer_alarm_id < 0)
59
{
60
DeleteSema(sema_id);
61
errno =
EAGAIN
;
// Resource temporarily unavailable
62
return
-1;
63
}
64
WaitSema(sema_id);
65
DeleteSema(sema_id);
66
67
if
(rem != NULL)
68
{
69
rem->tv_sec = 0;
70
rem->tv_nsec = 0;
71
}
72
73
return
0;
74
}
ENOSYS
#define ENOSYS
Definition
errno.h:194
EAGAIN
#define EAGAIN
Definition
errno.h:50
kernel.h
COP0_REG_Status
#define COP0_REG_Status
Definition
mipscopaccess.h:35
time.h
timer_alarm.h
SetTimerAlarm
s32 SetTimerAlarm(u64 clock_cycles, timer_alarm_handler_t callback_handler, void *arg)
Definition
timer_alarm.c:120
unistd.h
core
libcglue
src
sleep.c
Generated by
1.18.0