diff options
Diffstat (limited to 'libhw_generic/include/libhw/generic')
-rw-r--r-- | libhw_generic/include/libhw/generic/alarmclock.h | 70 |
1 files changed, 32 insertions, 38 deletions
diff --git a/libhw_generic/include/libhw/generic/alarmclock.h b/libhw_generic/include/libhw/generic/alarmclock.h index a9d816b..3817b4b 100644 --- a/libhw_generic/include/libhw/generic/alarmclock.h +++ b/libhw_generic/include/libhw/generic/alarmclock.h @@ -1,6 +1,6 @@ /* libhw/generic/alarmclock.h - Device-independent alarmclock definitions * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -11,7 +11,7 @@ #include <stdint.h> /* for uint{n}_t and UINT{n}_C */ #include <libmisc/private.h> -#include <libmisc/vcall.h> +#include <libobj/obj.h> /* Useful constants ***********************************************************/ @@ -35,59 +35,53 @@ struct alarmclock_trigger { /* Interface ******************************************************************/ -struct alarmclock_vtable; - -typedef struct { - struct alarmclock_vtable *vtable; -} implements_alarmclock; - -struct alarmclock_vtable { - /** - * (2⁶⁴-1 nanoseconds is more than 500 years; there is little - * risk of this overflowing) - */ - uint64_t (*get_time_ns)(implements_alarmclock *self); - - /** - * Returns true on error. - * - * Implementations may return an error if fire_at_ns is more - * than UINT32_MAX µs (72 minutes) in the future. - * - * If fire_at_ns is in the past, then it will fire - * immediately. - */ - bool (*add_trigger)(implements_alarmclock *self, struct alarmclock_trigger *trigger, - uint64_t fire_at_ns, - void (*cb)(void *), - void *cb_arg); - - void (*del_trigger)(implements_alarmclock *self, struct alarmclock_trigger *trigger); -}; +#define alarmclock_LO_IFACE \ + /** \ + * (2⁶⁴-1 nanoseconds is more than 500 years; there is little \ + * risk of this overflowing) \ + */ \ + LO_FUNC(uint64_t, get_time_ns) \ + \ + /** \ + * Returns true on error. \ + * \ + * Implementations may return an error if fire_at_ns is more \ + * than UINT32_MAX µs (72 minutes) in the future. \ + * \ + * If fire_at_ns is in the past, then it will fire \ + * immediately. \ + */ \ + LO_FUNC(bool, add_trigger, struct alarmclock_trigger *trigger, \ + uint64_t fire_at_ns, \ + void (*cb)(void *), \ + void *cb_arg) \ + \ + LO_FUNC(void, del_trigger, struct alarmclock_trigger *trigger) +LO_INTERFACE(alarmclock) /* Utilities ******************************************************************/ -void alarmclock_sleep_until_ns(implements_alarmclock *clock, uint64_t abstime_ns); +void alarmclock_sleep_until_ns(lo_interface alarmclock clock, uint64_t abstime_ns); -static inline void alarmclock_sleep_for_ns(implements_alarmclock *clock, uint64_t delta_ns) { - alarmclock_sleep_until_ns(clock, VCALL(clock, get_time_ns) + delta_ns); +static inline void alarmclock_sleep_for_ns(lo_interface alarmclock clock, uint64_t delta_ns) { + alarmclock_sleep_until_ns(clock, LO_CALL(clock, get_time_ns) + delta_ns); } -static inline void alarmclock_sleep_for_us(implements_alarmclock *clock, uint64_t delta_us) { +static inline void alarmclock_sleep_for_us(lo_interface alarmclock clock, uint64_t delta_us) { alarmclock_sleep_for_ns(clock, delta_us * (NS_PER_S/US_PER_S)); } -static inline void alarmclock_sleep_for_ms(implements_alarmclock *clock, uint64_t delta_ms) { +static inline void alarmclock_sleep_for_ms(lo_interface alarmclock clock, uint64_t delta_ms) { alarmclock_sleep_for_ns(clock, delta_ms * (NS_PER_S/MS_PER_S)); } -static inline void alarmclock_sleep_for_s(implements_alarmclock *clock, uint64_t delta_s) { +static inline void alarmclock_sleep_for_s(lo_interface alarmclock clock, uint64_t delta_s) { alarmclock_sleep_for_ns(clock, delta_s * NS_PER_S); } /* Globals ********************************************************************/ -extern implements_alarmclock *bootclock; +extern lo_interface alarmclock bootclock; #define sleep_until_ns(t) alarmclock_sleep_until_ns(bootclock, t) #define sleep_for_ns(t) alarmclock_sleep_for_ns(bootclock, t) |