1 /* 2 * Copyright (c) 2015 Wind River Systems, Inc. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_KERNEL_INCLUDE_TIMEOUT_Q_H_ 8 #define ZEPHYR_KERNEL_INCLUDE_TIMEOUT_Q_H_ 9 10 /** 11 * @file 12 * @brief timeout queue for threads on kernel objects 13 */ 14 15 #include <zephyr/kernel.h> 16 17 #include <stdbool.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #ifdef CONFIG_SYS_CLOCK_EXISTS 24 z_init_timeout(struct _timeout * to)25static inline void z_init_timeout(struct _timeout *to) 26 { 27 sys_dnode_init(&to->node); 28 } 29 30 void z_add_timeout(struct _timeout *to, _timeout_func_t fn, 31 k_timeout_t timeout); 32 33 int z_abort_timeout(struct _timeout *to); 34 z_is_inactive_timeout(const struct _timeout * to)35static inline bool z_is_inactive_timeout(const struct _timeout *to) 36 { 37 return !sys_dnode_is_linked(&to->node); 38 } 39 z_init_thread_timeout(struct _thread_base * thread_base)40static inline void z_init_thread_timeout(struct _thread_base *thread_base) 41 { 42 z_init_timeout(&thread_base->timeout); 43 } 44 45 extern void z_thread_timeout(struct _timeout *timeout); 46 z_add_thread_timeout(struct k_thread * thread,k_timeout_t ticks)47static inline void z_add_thread_timeout(struct k_thread *thread, k_timeout_t ticks) 48 { 49 z_add_timeout(&thread->base.timeout, z_thread_timeout, ticks); 50 } 51 z_abort_thread_timeout(struct k_thread * thread)52static inline int z_abort_thread_timeout(struct k_thread *thread) 53 { 54 return z_abort_timeout(&thread->base.timeout); 55 } 56 57 int32_t z_get_next_timeout_expiry(void); 58 59 k_ticks_t z_timeout_remaining(const struct _timeout *timeout); 60 61 #else 62 63 /* Stubs when !CONFIG_SYS_CLOCK_EXISTS */ 64 #define z_init_thread_timeout(thread_base) do {} while (false) 65 #define z_abort_thread_timeout(to) (0) 66 #define z_is_inactive_timeout(to) 0 67 #define z_get_next_timeout_expiry() ((int32_t) K_TICKS_FOREVER) 68 #define z_set_timeout_expiry(ticks, is_idle) do {} while (false) 69 70 static inline void z_add_thread_timeout(struct k_thread *thread, k_timeout_t ticks) 71 { 72 ARG_UNUSED(thread); 73 ARG_UNUSED(ticks); 74 } 75 76 #endif 77 78 #ifdef __cplusplus 79 } 80 #endif 81 82 #endif /* ZEPHYR_KERNEL_INCLUDE_TIMEOUT_Q_H_ */ 83