From 3231a1296d7194f85451f0b2f9d048c845705c5b Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 5 Jan 2024 22:15:06 +0100 Subject: [PATCH] libc: Add support for POSIX timers --- libc/include/time.h | 15 +++++++++++++++ libc/src/time.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/libc/include/time.h b/libc/include/time.h index 3e725293..2e1ae73b 100644 --- a/libc/include/time.h +++ b/libc/include/time.h @@ -4,8 +4,11 @@ #define _TIME_H #include +#include +#include #include #include +#include typedef long int clock_t; @@ -58,6 +61,18 @@ extern "C" /* Estimate the CPU time used by a process. */ clock_t clock(void); + /* Create a new POSIX timer. */ + int timer_create(clockid_t clockid, struct sigevent* sevp, timer_t* timerid); + + /* Get the current time remaining for a POSIX timer. */ + int timer_gettime(timer_t timerid, struct itimerspec* value); + + /* Set the time remaining and interval for a POSIX timer. */ + int timer_settime(timer_t timerid, int flags, const struct itimerspec* new_value, struct itimerspec* old_value); + + /* Delete an existing POSIX timer. */ + int timer_delete(timer_t timerid); + #ifdef __cplusplus } #endif diff --git a/libc/src/time.cpp b/libc/src/time.cpp index 3f2bb102..238663b6 100644 --- a/libc/src/time.cpp +++ b/libc/src/time.cpp @@ -206,4 +206,28 @@ extern "C" long rc = syscall(SYS_setitimer, which, new_timer, old_timer); __errno_return(rc, int); } + + int timer_create(clockid_t clockid, struct sigevent* sevp, timer_t* timerid) + { + long rc = syscall(SYS_timer_create, clockid, sevp, timerid); + __errno_return(rc, int); + } + + int timer_gettime(timer_t timerid, struct itimerspec* value) + { + long rc = syscall(SYS_timer_gettime, timerid, value); + __errno_return(rc, int); + } + + int timer_settime(timer_t timerid, int flags, const struct itimerspec* new_value, struct itimerspec* old_value) + { + long rc = syscall(SYS_timer_settime, timerid, flags, new_value, old_value); + __errno_return(rc, int); + } + + int timer_delete(timer_t timerid) + { + long rc = syscall(SYS_timer_delete, timerid); + __errno_return(rc, int); + } }