Skip to content

Commit

Permalink
Merge pull request #4106 from yeongjukang/master
Browse files Browse the repository at this point in the history
core:sys/linux - implement clock_settime, clock_getres and clock_nanosleep
  • Loading branch information
gingerBill committed Aug 21, 2024
2 parents 0d39f52 + bbe4c32 commit e7b8e61
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions core/sys/linux/sys.odin
Original file line number Diff line number Diff line change
Expand Up @@ -2404,17 +2404,44 @@ timer_delete :: proc "contextless" (timer: Timer) -> (Errno) {
return Errno(-ret)
}

// TODO(flysand): clock_settime
/*
Set the time of the specified clock.
Available since Linux 2.6.
*/
clock_settime :: proc "contextless" (clock: Clock_Id, ts: ^Time_Spec) -> (Errno) {
ret := syscall(SYS_clock_settime, clock, ts)
return Errno(-ret)
}

/*
Retrieve the time of the specified clock.
Available since Linux 2.6.
*/
clock_gettime :: proc "contextless" (clock: Clock_Id) -> (ts: Time_Spec, err: Errno) {
ret := syscall(SYS_clock_gettime, clock, &ts)
err = Errno(-ret)
return
}

// TODO(flysand): clock_getres

// TODO(flysand): clock_nanosleep
/*
Finds the resolution of the specified clock.
Available since Linux 2.6.
*/
clock_getres :: proc "contextless" (clock: Clock_Id) -> (res: Time_Spec, err: Errno) {
ret := syscall(SYS_clock_getres, clock, &res)
err = Errno(-ret)
return
}

/*
Sleep for an interval specified with nanosecond precision.
Available since Linux 2.6.
*/
clock_nanosleep :: proc "contextless" (clock: Clock_Id, flags: ITimer_Flags, request: ^Time_Spec, remain: ^Time_Spec) -> (Errno) {
ret := syscall(SYS_clock_nanosleep, clock, transmute(u32) flags, request, remain)
return Errno(-ret)
}

/*
Exit the thread group.
Expand Down

0 comments on commit e7b8e61

Please sign in to comment.