authorgravatar for devnexen@gmail.comDavid Carlier <devnexen@gmail.com> 2023-05-18 21:09:46+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-05-19 03:41:10+03:00
logb9d2e0e308794463db1b1acf04d76778c470a070
treea521fd9cd0f4bb700e02a59d26481ea772388e94
parentad391ad399b26cf6a781e01c6daecf48bb764478

std.os: add linux timer api


1 files changed, 37 insertions(+), 0 deletions(-)

lib/std/os/linux.zig+37
......@@ -1590,6 +1590,43 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_va
15901590 return syscall4(.timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
15911591}
15921592
1593pub const sigevent = extern struct {
1594 value: sigval,
1595 signo: i32,
1596 inotify: i32,
1597 libc_priv_impl: opaque {},
1598};
1599
1600// Flags for sigevent sigev_inotify's field
1601pub const SIGEV = enum(i32) {
1602 NONE = 0,
1603 SIGNAL = 1,
1604 THREAD = 2,
1605 THREAD_ID = 4,
1606};
1607
1608pub const timer_t = ?*anyopaque;
1609
1610pub fn timer_create(clockid: i32, sevp: *sigevent, timerid: *timer_t) usize {
1611 var t: timer_t = undefined;
1612 const rc = syscall3(.timer_create, @bitCast(usize, @as(isize, clockid)), @ptrToInt(sevp), @ptrToInt(&t));
1613 if (@bitCast(isize, rc) < 0) return rc;
1614 timerid.* = t;
1615 return rc;
1616}
1617
1618pub fn timer_delete(timerid: timer_t) usize {
1619 return syscall1(.timer_delete, timerid);
1620}
1621
1622pub fn timer_gettime(timerid: timer_t, curr_value: *itimerspec) usize {
1623 return syscall2(.timer_gettime, @ptrToInt(timerid), @ptrToInt(curr_value));
1624}
1625
1626pub fn timer_settime(timerid: timer_t, flags: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1627 return syscall4(.timer_settime, @ptrToInt(timerid), @bitCast(usize, @as(isize, flags)), @ptrToInt(new_value), @ptrToInt(old_value));
1628}
1629
15931630// Flags for the 'setitimer' system call
15941631pub const ITIMER = enum(i32) {
15951632 REAL = 0,