From 6c114930eef133293856189a93f7ca7ca3751268 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 29 Oct 2024 20:20:07 -0600 Subject: wip host_alarmclock --- libhw/host_sigrt.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 libhw/host_sigrt.h (limited to 'libhw/host_sigrt.h') diff --git a/libhw/host_sigrt.h b/libhw/host_sigrt.h new file mode 100644 index 0000000..fa5675b --- /dev/null +++ b/libhw/host_sigrt.h @@ -0,0 +1,47 @@ +/* libhw/host_sigrt.h - Manage glibc realtime signals + * + * Copyright (C) 2024 Luke T. Shumaker + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _LIBHW_HOST_SIGRT_H_ +#define _LIBHW_HOST_SIGRT_H_ + +#include /* for struct timespec */ +#include /* for struct timeval */ + +#include /* for {X}S_PER_S */ + +int host_sigrt_alloc(void); + +typedef struct timeval host_us_time_t; +typedef struct timespec host_ns_time_t; + +static inline host_us_time_t ns_to_host_us_time(uint64_t time_ns) { + host_us_time_t ret; + ret.tv_sec = time_ns + /NS_PER_S; + ret.tv_usec = (time_ns - ((uint64_t)ret.tv_sec)*NS_PER_S) + /(NS_PER_S/US_PER_S); + return ret; +} + +static inline host_ns_time_t ns_to_host_ns_time(uint64_t time_ns) { + host_ns_time_t ret; + ret.tv_sec = time_ns + /NS_PER_S; + ret.tv_nsec = time_ns - ((uint64_t)ret.tv_sec)*NS_PER_S; + return ret; +} + +static inline uint64_t ns_from_host_us_time(host_us_time_t host_time) { + return (((uint64_t)ts.tv_sec) * NS_PER_S) + + ((uint64_t)ts.tv_nsec * (NS_PER_S/US_PER_S)); +} + +static inline uint64_t ns_from_host_ns_time(host_ns_time_t host_time) { + return (((uint64_t)ts.tv_sec) * NS_PER_S) + + ((uint64_t)ts.tv_nsec); +} + +#endif /* _LIBHW_HOST_SIGRT_H_ */ -- cgit v1.2.3-2-g168b