Skip to content

Commit

Permalink
std.os: add linux timer api
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen authored and Vexu committed May 19, 2023
1 parent ad391ad commit b9d2e0e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/std/os/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,43 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_va
return syscall4(.timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
}

pub const sigevent = extern struct {
value: sigval,
signo: i32,
inotify: i32,
libc_priv_impl: opaque {},
};

// Flags for sigevent sigev_inotify's field
pub const SIGEV = enum(i32) {

This comment has been minimized.

Copy link
@sergpolkin

sergpolkin Jun 3, 2023

Contributor

Incorrect defines for SIGEV
From siginfo.h:

#define SIGEV_SIGNAL	0	/* notify via signal */
#define SIGEV_NONE	1	/* other notification: meaningless */
#define SIGEV_THREAD	2	/* deliver via thread creation */
#define SIGEV_THREAD_ID 4	/* deliver to thread */
NONE = 0,
SIGNAL = 1,
THREAD = 2,
THREAD_ID = 4,
};

pub const timer_t = ?*anyopaque;

pub fn timer_create(clockid: i32, sevp: *sigevent, timerid: *timer_t) usize {
var t: timer_t = undefined;
const rc = syscall3(.timer_create, @bitCast(usize, @as(isize, clockid)), @ptrToInt(sevp), @ptrToInt(&t));
if (@bitCast(isize, rc) < 0) return rc;
timerid.* = t;
return rc;
}

pub fn timer_delete(timerid: timer_t) usize {
return syscall1(.timer_delete, timerid);
}

pub fn timer_gettime(timerid: timer_t, curr_value: *itimerspec) usize {
return syscall2(.timer_gettime, @ptrToInt(timerid), @ptrToInt(curr_value));
}

pub fn timer_settime(timerid: timer_t, flags: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
return syscall4(.timer_settime, @ptrToInt(timerid), @bitCast(usize, @as(isize, flags)), @ptrToInt(new_value), @ptrToInt(old_value));
}

// Flags for the 'setitimer' system call
pub const ITIMER = enum(i32) {
REAL = 0,
Expand Down

0 comments on commit b9d2e0e

Please sign in to comment.