diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-26 22:18:47 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-26 22:18:47 -0600 |
commit | 6ab74d74ee6dc1663b66d0a9a0471f63ade5659a (patch) | |
tree | b579303cc5df38191ee9e8ad63793fbe4c867c02 /libhw_cr/alarmclock.c | |
parent | 9f2e2e96321f14da97adda618a7e4721cbb9791c (diff) | |
parent | 865bb702f828784a0225b5eae9ed8803094140d5 (diff) |
Merge branch 'lukeshu/9p-read-iovec'
Diffstat (limited to 'libhw_cr/alarmclock.c')
-rw-r--r-- | libhw_cr/alarmclock.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libhw_cr/alarmclock.c b/libhw_cr/alarmclock.c new file mode 100644 index 0000000..6eec52b --- /dev/null +++ b/libhw_cr/alarmclock.c @@ -0,0 +1,23 @@ +/* libhw_cr/alarmclock.c - sleep() implementation for libcr + * + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include <libcr/coroutine.h> + +#include <libhw/generic/alarmclock.h> + +static void alarmclock_sleep_intrhandler(void *_arg) { + cid_t cid = *(cid_t *)_arg; + cr_unpause_from_intrhandler(cid); +} + +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; + LO_CALL(clock, add_trigger, &trigger, abstime_ns, alarmclock_sleep_intrhandler, &cid); + cr_pause_and_yield(); + cr_restore_interrupts(saved); +} |