diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-02-02 02:01:30 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-02-09 23:42:11 -0700 |
commit | 41ac4f8dfddc8d003cb3174d466a58fa14701d35 (patch) | |
tree | 209bbac2078be812aa4f20e2a146e471a7e2c99b | |
parent | 9cd5486484653dd8cc42b43bcde45379982c3177 (diff) |
libhw_generic: alarmclock: Use libobj instead of vcall.h
-rw-r--r-- | lib9p/tests/test_server/main.c | 4 | ||||
-rw-r--r-- | libdhcp/dhcp_client.c | 8 | ||||
-rw-r--r-- | libhw/host_alarmclock.c | 43 | ||||
-rw-r--r-- | libhw/host_include/libhw/host_alarmclock.h | 4 | ||||
-rw-r--r-- | libhw/host_net.c | 4 | ||||
-rw-r--r-- | libhw/rp2040_hwtimer.c | 42 | ||||
-rw-r--r-- | libhw/rp2040_include/libhw/rp2040_hwtimer.h | 2 | ||||
-rw-r--r-- | libhw/w5500.c | 32 | ||||
-rw-r--r-- | libhw_generic/CMakeLists.txt | 3 | ||||
-rw-r--r-- | libhw_generic/alarmclock.c | 7 | ||||
-rw-r--r-- | libhw_generic/include/libhw/generic/alarmclock.h | 70 |
11 files changed, 84 insertions, 135 deletions
diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c index b979a4b..8df3da0 100644 --- a/lib9p/tests/test_server/main.c +++ b/lib9p/tests/test_server/main.c @@ -13,6 +13,7 @@ #include <libhw/host_alarmclock.h> #include <libhw/host_net.h> #include <libmisc/macro.h> +#include <libmisc/vcall.h> #include <util9p/static.h> #include "static.h" @@ -195,10 +196,9 @@ static COROUTINE init_cr(void *) { int main() { struct hostclock clock_monotonic = { - .vtable = &hostclock_vtable, .clock_id = CLOCK_MONOTONIC, }; - bootclock = &clock_monotonic; + bootclock = lo_box_hostclock_as_alarmclock(&clock_monotonic); coroutine_add("init", init_cr, NULL); coroutine_main(); return 0; diff --git a/libdhcp/dhcp_client.c b/libdhcp/dhcp_client.c index ea6ed28..d6b2f19 100644 --- a/libdhcp/dhcp_client.c +++ b/libdhcp/dhcp_client.c @@ -1,6 +1,6 @@ /* libdhcp/dhcp_client.c - A DHCP client * - * 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 * * ----------------------------------------------------------------------------- @@ -313,7 +313,7 @@ static bool dhcp_client_send(struct dhcp_client *client, uint8_t msgtyp, const c switch (msgtyp) { case DHCP_MSGTYP_DISCOVER: case DHCP_MSGTYP_INFORM: case DHCP_MSGTYP_REQUEST: - secs = (VCALL(bootclock, get_time_ns) - client->time_ns_init)/NS_PER_S; + secs = (LO_CALL(bootclock, get_time_ns) - client->time_ns_init)/NS_PER_S; if (!secs) /* systemd's sd-dhcp-client.c asserts that some * servers are broken and require .secs to be @@ -772,7 +772,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, switch (client->state) { case STATE_INIT: client->xid = rand_uint63n(UINT32_MAX); - client->time_ns_init = VCALL(bootclock, get_time_ns); + client->time_ns_init = LO_CALL(bootclock, get_time_ns); dhcp_client_setstate(client, STATE_SELECTING, DHCP_MSGTYP_DISCOVER, NULL, scratch_msg); break; case STATE_SELECTING: @@ -840,7 +840,7 @@ static void dhcp_client_setstate(struct dhcp_client *client, break; case STATE_RENEWING: client->xid = rand_uint63n(UINT32_MAX); - client->time_ns_init = VCALL(bootclock, get_time_ns); + client->time_ns_init = LO_CALL(bootclock, get_time_ns); VCALL(client->sock, set_read_deadline, client->lease_time_ns_t2); switch ((r = dhcp_client_recv(client, scratch_msg))) { diff --git a/libhw/host_alarmclock.c b/libhw/host_alarmclock.c index bb1821a..19ece7c 100644 --- a/libhw/host_alarmclock.c +++ b/libhw/host_alarmclock.c @@ -10,7 +10,6 @@ #include <libcr/coroutine.h> #include <libmisc/assert.h> -#include <libmisc/vcall.h> #define IMPLEMENTATION_FOR_LIBHW_GENERIC_ALARMCLOCK_H YES #include <libhw/generic/alarmclock.h> @@ -20,28 +19,9 @@ #include "host_util.h" /* for host_sigrt_alloc(), ns_to_host_ns_time() */ -/* Globals ********************************************************************/ +LO_IMPLEMENTATION_C(alarmclock, struct hostclock, hostclock, static) -static uint64_t hostclock_get_time_ns(implements_alarmclock *self); -static bool hostclock_add_trigger(implements_alarmclock *self, - struct alarmclock_trigger *trigger, - uint64_t fire_at_ns, - void (*cb)(void *), - void *cb_arg); -static void hostclock_del_trigger(implements_alarmclock *self, - struct alarmclock_trigger *trigger); - -struct alarmclock_vtable hostclock_vtable = { - .get_time_ns = hostclock_get_time_ns, - .add_trigger = hostclock_add_trigger, - .del_trigger = hostclock_del_trigger, -}; - -/* Main implementation ********************************************************/ - -static uint64_t hostclock_get_time_ns(implements_alarmclock *_alarmclock) { - struct hostclock *alarmclock = - VCALL_SELF(struct hostclock, implements_alarmclock, _alarmclock); +static uint64_t hostclock_get_time_ns(struct hostclock *alarmclock) { assert(alarmclock); struct timespec ts; @@ -76,13 +56,11 @@ static void hostclock_handle_sig_alarm(int LM_UNUSED(sig), siginfo_t *info, void } } -static bool hostclock_add_trigger(implements_alarmclock *_alarmclock, - struct alarmclock_trigger *trigger, - uint64_t fire_at_ns, - void (*cb)(void *), - void *cb_arg) { - struct hostclock *alarmclock = - VCALL_SELF(struct hostclock, implements_alarmclock, _alarmclock); +static bool hostclock_add_trigger(struct hostclock *alarmclock, + struct alarmclock_trigger *trigger, + uint64_t fire_at_ns, + void (*cb)(void *), + void *cb_arg) { assert(alarmclock); assert(trigger); assert(fire_at_ns); @@ -133,11 +111,8 @@ static bool hostclock_add_trigger(implements_alarmclock *_alarmclock, return false; } -static void hostclock_del_trigger(implements_alarmclock *_alarmclock, - struct alarmclock_trigger *trigger) { - struct hostclock *alarmclock = - VCALL_SELF(struct hostclock, implements_alarmclock, _alarmclock); - +static void hostclock_del_trigger(struct hostclock *alarmclock, + struct alarmclock_trigger *trigger) { assert(alarmclock); assert(trigger); diff --git a/libhw/host_include/libhw/host_alarmclock.h b/libhw/host_include/libhw/host_alarmclock.h index 163fb9f..89df68a 100644 --- a/libhw/host_include/libhw/host_alarmclock.h +++ b/libhw/host_include/libhw/host_alarmclock.h @@ -14,7 +14,6 @@ #include <libhw/generic/alarmclock.h> struct hostclock { - implements_alarmclock; clockid_t clock_id; BEGIN_PRIVATE(LIBHW_HOST_ALARMCLOCK_H) @@ -23,7 +22,6 @@ struct hostclock { struct alarmclock_trigger *queue; END_PRIVATE(LIBHW_HOST_ALARMCLOCK_H) }; - -extern struct alarmclock_vtable hostclock_vtable; +LO_IMPLEMENTATION_H(alarmclock, struct hostclock, hostclock) #endif /* _LIBHW_HOST_ALARMCLOCK_H_ */ diff --git a/libhw/host_net.c b/libhw/host_net.c index bf79480..3352b87 100644 --- a/libhw/host_net.c +++ b/libhw/host_net.c @@ -267,7 +267,7 @@ static ssize_t hostnet_tcp_read(implements_net_stream_conn *_conn, void *buf, si .ret = &ret, }; if (conn->read_deadline_ns) { - uint64_t now_ns = VCALL(bootclock, get_time_ns); + uint64_t now_ns = LO_CALL(bootclock, get_time_ns); if (conn->read_deadline_ns < now_ns) return -NET_ERECV_TIMEOUT; args.timeout = ns_to_host_us_time(conn->read_deadline_ns-now_ns); @@ -534,7 +534,7 @@ static ssize_t hostnet_udp_recvfrom(implements_net_packet_conn *_conn, void *buf .ret_port = ret_port, }; if (conn->read_deadline_ns) { - uint64_t now_ns = VCALL(bootclock, get_time_ns); + uint64_t now_ns = LO_CALL(bootclock, get_time_ns); if (conn->read_deadline_ns < now_ns) return -NET_ERECV_TIMEOUT; args.timeout = ns_to_host_us_time(conn->read_deadline_ns-now_ns); diff --git a/libhw/rp2040_hwtimer.c b/libhw/rp2040_hwtimer.c index 6c871a3..ada6246 100644 --- a/libhw/rp2040_hwtimer.c +++ b/libhw/rp2040_hwtimer.c @@ -9,10 +9,10 @@ #include <libcr/coroutine.h> #include <libmisc/assert.h> -#include <libmisc/vcall.h> #define IMPLEMENTATION_FOR_LIBHW_GENERIC_ALARMCLOCK_H YES #include <libhw/generic/alarmclock.h> + #include <libhw/rp2040_hwtimer.h> /******************************************************************************/ @@ -23,46 +23,32 @@ void add_alarm_at(void) {}; /* Types **********************************************************************/ struct rp2040_hwtimer { - implements_alarmclock; enum rp2040_hwalarm_instance alarm_num; bool initialized; struct alarmclock_trigger *queue; }; +LO_IMPLEMENTATION_H(alarmclock, struct rp2040_hwtimer, rp2040_hwtimer); +LO_IMPLEMENTATION_C(alarmclock, struct rp2040_hwtimer, rp2040_hwtimer, static); /* Globals ********************************************************************/ -static uint64_t rp2040_hwtimer_get_time_ns(implements_alarmclock *self); -static bool rp2040_hwtimer_add_trigger(implements_alarmclock *self, - struct alarmclock_trigger *trigger, - uint64_t fire_at_ns, - void (*cb)(void *), - void *cb_arg); -static void rp2040_hwtimer_del_trigger(implements_alarmclock *self, - struct alarmclock_trigger *trigger); - -static struct alarmclock_vtable rp2040_hwtimer_vtable = { - .get_time_ns = rp2040_hwtimer_get_time_ns, - .add_trigger = rp2040_hwtimer_add_trigger, - .del_trigger = rp2040_hwtimer_del_trigger, -}; - static struct rp2040_hwtimer hwtimers[] = { - { .vtable = &rp2040_hwtimer_vtable, .alarm_num = 0 }, - { .vtable = &rp2040_hwtimer_vtable, .alarm_num = 1 }, - { .vtable = &rp2040_hwtimer_vtable, .alarm_num = 2 }, - { .vtable = &rp2040_hwtimer_vtable, .alarm_num = 3 }, + { .alarm_num = 0 }, + { .alarm_num = 1 }, + { .alarm_num = 2 }, + { .alarm_num = 3 }, }; static_assert(sizeof(hwtimers)/sizeof(hwtimers[0]) == _RP2040_HWALARM_NUM); /* Main implementation ********************************************************/ -implements_alarmclock *rp2040_hwtimer(enum rp2040_hwalarm_instance alarm_num) { +lo_interface alarmclock rp2040_hwtimer(enum rp2040_hwalarm_instance alarm_num) { assert(alarm_num < _RP2040_HWALARM_NUM); - return &hwtimers[alarm_num]; + return lo_box_rp2040_hwtimer_as_alarmclock(&hwtimers[alarm_num]); } -static uint64_t rp2040_hwtimer_get_time_ns(implements_alarmclock *) { +static uint64_t rp2040_hwtimer_get_time_ns(struct rp2040_hwtimer *) { return timer_time_us_64(timer_hw) * (NS_PER_S/US_PER_S); } @@ -91,13 +77,11 @@ static void rp2040_hwtimer_intrhandler(void) { timer_hw->alarm[alarm_num] = (uint32_t)NS_TO_US_ROUNDUP(alarmclock->queue->fire_at_ns); } -static bool rp2040_hwtimer_add_trigger(implements_alarmclock *_alarmclock, +static bool rp2040_hwtimer_add_trigger(struct rp2040_hwtimer *alarmclock, struct alarmclock_trigger *trigger, uint64_t fire_at_ns, void (*cb)(void *), void *cb_arg) { - struct rp2040_hwtimer *alarmclock = - VCALL_SELF(struct rp2040_hwtimer, implements_alarmclock, _alarmclock); assert(alarmclock); assert(trigger); assert(fire_at_ns); @@ -147,10 +131,8 @@ static bool rp2040_hwtimer_add_trigger(implements_alarmclock *_alarmclock, return false; } -static void rp2040_hwtimer_del_trigger(implements_alarmclock *_alarmclock, +static void rp2040_hwtimer_del_trigger(struct rp2040_hwtimer *alarmclock, struct alarmclock_trigger *trigger) { - struct rp2040_hwtimer *alarmclock = - VCALL_SELF(struct rp2040_hwtimer, implements_alarmclock, _alarmclock); assert(alarmclock); assert(trigger); diff --git a/libhw/rp2040_include/libhw/rp2040_hwtimer.h b/libhw/rp2040_include/libhw/rp2040_hwtimer.h index 645ba20..40e4172 100644 --- a/libhw/rp2040_include/libhw/rp2040_hwtimer.h +++ b/libhw/rp2040_include/libhw/rp2040_hwtimer.h @@ -20,6 +20,6 @@ enum rp2040_hwalarm_instance { _RP2040_HWALARM_NUM, }; -implements_alarmclock *rp2040_hwtimer(enum rp2040_hwalarm_instance alarm_num); +lo_interface alarmclock rp2040_hwtimer(enum rp2040_hwalarm_instance alarm_num); #endif /* _LIBHW_RP2040_HWTIMER_H_ */ diff --git a/libhw/w5500.c b/libhw/w5500.c index cebcf8e..5a9a718 100644 --- a/libhw/w5500.c +++ b/libhw/w5500.c @@ -1,6 +1,6 @@ /* libhw/w5500.c - <libhw/generic/net.h> implementation for the WIZnet W5500 chip * - * 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 * * ----------------------------------------------------------------------------- @@ -744,7 +744,7 @@ static ssize_t w5500_tcp_read(implements_net_stream_conn *_socket, void *buf, si struct alarmclock_trigger trigger = {0}; if (socket->read_deadline_ns) - VCALL(bootclock, add_trigger, &trigger, + LO_CALL(bootclock, add_trigger, &trigger, socket->read_deadline_ns, w5500_tcp_alarm_handler, socket); @@ -753,12 +753,12 @@ static ssize_t w5500_tcp_read(implements_net_stream_conn *_socket, void *buf, si uint16_t avail = 0; for (;;) { if (!socket->read_open) { - VCALL(bootclock, del_trigger, &trigger); + LO_CALL(bootclock, del_trigger, &trigger); debugf(" => soft closed"); return -NET_ECLOSED; } - if (socket->read_deadline_ns && socket->read_deadline_ns <= VCALL(bootclock, get_time_ns)) { - VCALL(bootclock, del_trigger, &trigger); + if (socket->read_deadline_ns && socket->read_deadline_ns <= LO_CALL(bootclock, get_time_ns)) { + LO_CALL(bootclock, del_trigger, &trigger); debugf(" => recv timeout"); return -NET_ERECV_TIMEOUT; } @@ -770,7 +770,7 @@ static ssize_t w5500_tcp_read(implements_net_stream_conn *_socket, void *buf, si case STATE_TCP_FIN_WAIT: break; /* OK */ default: - VCALL(bootclock, del_trigger, &trigger); + LO_CALL(bootclock, del_trigger, &trigger); cr_mutex_unlock(&chip->mu); debugf(" => hard closed"); return -NET_ECLOSED; @@ -781,7 +781,7 @@ static ssize_t w5500_tcp_read(implements_net_stream_conn *_socket, void *buf, si /* We have data to read. */ break; if (state == STATE_TCP_CLOSE_WAIT) { - VCALL(bootclock, del_trigger, &trigger); + LO_CALL(bootclock, del_trigger, &trigger); cr_mutex_unlock(&chip->mu); debugf(" => EOF"); return 0; @@ -801,7 +801,7 @@ static ssize_t w5500_tcp_read(implements_net_stream_conn *_socket, void *buf, si w5500ll_write_sock_reg(chip->spidev, socknum, rx_read_pointer, uint16be_marshal(ptr+avail)); w5500_socket_cmd(socket, CMD_RECV); /* Return. */ - VCALL(bootclock, del_trigger, &trigger); + LO_CALL(bootclock, del_trigger, &trigger); cr_mutex_unlock(&chip->mu); return avail; } @@ -916,23 +916,23 @@ static ssize_t w5500_udp_recvfrom(implements_net_packet_conn *_socket, void *buf struct alarmclock_trigger trigger = {0}; if (socket->read_deadline_ns) - VCALL(bootclock, add_trigger, &trigger, - socket->read_deadline_ns, - w5500_udp_alarm_handler, - socket); + LO_CALL(bootclock, add_trigger, &trigger, + socket->read_deadline_ns, + w5500_udp_alarm_handler, + socket); /* Wait until there is data to read. */ uint16_t avail = 0; for (;;) { - if (socket->read_deadline_ns && socket->read_deadline_ns <= VCALL(bootclock, get_time_ns)) { - VCALL(bootclock, del_trigger, &trigger); + if (socket->read_deadline_ns && socket->read_deadline_ns <= LO_CALL(bootclock, get_time_ns)) { + LO_CALL(bootclock, del_trigger, &trigger); debugf(" => recv timeout"); return -NET_ERECV_TIMEOUT; } cr_mutex_lock(&chip->mu); uint8_t state = w5500ll_read_sock_reg(chip->spidev, socknum, state); if (state != STATE_UDP) { - VCALL(bootclock, del_trigger, &trigger); + LO_CALL(bootclock, del_trigger, &trigger); debugf(" => hard closed"); return -NET_ECLOSED; } @@ -970,7 +970,7 @@ static ssize_t w5500_udp_recvfrom(implements_net_packet_conn *_socket, void *buf w5500ll_write_sock_reg(chip->spidev, socknum, rx_read_pointer, uint16be_marshal(ptr+8+len)); w5500_socket_cmd(socket, CMD_RECV); /* Return. */ - VCALL(bootclock, del_trigger, &trigger); + LO_CALL(bootclock, del_trigger, &trigger); cr_mutex_unlock(&chip->mu); return len; } diff --git a/libhw_generic/CMakeLists.txt b/libhw_generic/CMakeLists.txt index 0356770..e38fbe9 100644 --- a/libhw_generic/CMakeLists.txt +++ b/libhw_generic/CMakeLists.txt @@ -1,12 +1,13 @@ # libhw_generic/CMakeLists.txt - UAPI device interfaces # -# 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 add_library(libhw_generic INTERFACE) target_include_directories(libhw_generic SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(libhw_generic INTERFACE libmisc + libobj libcr ) diff --git a/libhw_generic/alarmclock.c b/libhw_generic/alarmclock.c index d501f51..7fd049e 100644 --- a/libhw_generic/alarmclock.c +++ b/libhw_generic/alarmclock.c @@ -5,22 +5,21 @@ */ #include <libcr/coroutine.h> -#include <libmisc/vcall.h> #include <libhw/generic/alarmclock.h> -implements_alarmclock *bootclock = NULL; +lo_interface alarmclock bootclock = {0}; static void alarmclock_sleep_intrhandler(void *_arg) { cid_t cid = *(cid_t *)_arg; cr_unpause_from_intrhandler(cid); } -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) { bool saved = cr_save_and_disable_interrupts(); cid_t cid = cr_getcid(); struct alarmclock_trigger trigger; - VCALL(clock, add_trigger, &trigger, abstime_ns, alarmclock_sleep_intrhandler, &cid); + LO_CALL(clock, add_trigger, &trigger, abstime_ns, alarmclock_sleep_intrhandler, &cid); cr_pause_and_yield(); cr_restore_interrupts(saved); } 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) |