1 /* wait queue for multiple threads on kernel objects */ 2 3 /* 4 * Copyright (c) 2015 Wind River Systems, Inc. 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 #ifndef ZEPHYR_KERNEL_INCLUDE_WAIT_Q_H_ 10 #define ZEPHYR_KERNEL_INCLUDE_WAIT_Q_H_ 11 12 #include <kernel_structs.h> 13 #include <sys/dlist.h> 14 #include <sys/rb.h> 15 #include <kernel/sched_priq.h> 16 #include <timeout_q.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #ifdef CONFIG_WAITQ_SCALABLE 23 24 #define _WAIT_Q_FOR_EACH(wq, thread_ptr) \ 25 RB_FOR_EACH_CONTAINER(&(wq)->waitq.tree, thread_ptr, base.qnode_rb) 26 z_waitq_init(_wait_q_t * w)27static inline void z_waitq_init(_wait_q_t *w) 28 { 29 w->waitq = (struct _priq_rb) { 30 .tree = { 31 .lessthan_fn = z_priq_rb_lessthan 32 } 33 }; 34 } 35 z_waitq_head(_wait_q_t * w)36static inline struct k_thread *z_waitq_head(_wait_q_t *w) 37 { 38 return (struct k_thread *)rb_get_min(&w->waitq.tree); 39 } 40 41 #else /* !CONFIG_WAITQ_SCALABLE: */ 42 43 #define _WAIT_Q_FOR_EACH(wq, thread_ptr) \ 44 SYS_DLIST_FOR_EACH_CONTAINER(&((wq)->waitq), thread_ptr, \ 45 base.qnode_dlist) 46 47 static inline void z_waitq_init(_wait_q_t *w) 48 { 49 sys_dlist_init(&w->waitq); 50 } 51 52 static inline struct k_thread *z_waitq_head(_wait_q_t *w) 53 { 54 return (struct k_thread *)sys_dlist_peek_head(&w->waitq); 55 } 56 57 #endif /* !CONFIG_WAITQ_SCALABLE */ 58 59 #ifdef __cplusplus 60 } 61 #endif 62 63 #endif /* ZEPHYR_KERNEL_INCLUDE_WAIT_Q_H_ */ 64