Anas Nashif | cb888e6 | 2016-12-18 09:42:55 -0500 | [diff] [blame] | 1 | /* wait queue for multiple threads on kernel objects */ |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2015 Wind River Systems, Inc. |
| 5 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 6 | * SPDX-License-Identifier: Apache-2.0 |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
Flavio Ceolin | a7fffa9 | 2018-09-13 15:06:35 -0700 | [diff] [blame] | 9 | #ifndef ZEPHYR_KERNEL_INCLUDE_WAIT_Q_H_ |
| 10 | #define ZEPHYR_KERNEL_INCLUDE_WAIT_Q_H_ |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 11 | |
Benjamin Walsh | f6ca7de | 2016-11-08 10:36:50 -0500 | [diff] [blame] | 12 | #include <kernel_structs.h> |
Anas Nashif | ee9dd1a | 2019-06-26 10:33:41 -0400 | [diff] [blame] | 13 | #include <sys/dlist.h> |
Anas Nashif | 1859244 | 2019-06-26 10:33:50 -0400 | [diff] [blame] | 14 | #include <sys/rb.h> |
Andy Ross | 1acd8c2 | 2018-05-03 14:51:49 -0700 | [diff] [blame] | 15 | #include <sched_priq.h> |
Andy Ross | 2ae8f50 | 2018-09-26 12:48:15 -0700 | [diff] [blame] | 16 | #include <timeout_q.h> |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
Andy Ross | 225c74b | 2018-06-27 11:20:50 -0700 | [diff] [blame] | 22 | #ifdef CONFIG_WAITQ_SCALABLE |
Andy Ross | 1acd8c2 | 2018-05-03 14:51:49 -0700 | [diff] [blame] | 23 | |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 24 | #define _WAIT_Q_FOR_EACH(wq, thread_ptr) \ |
Andy Ross | 1acd8c2 | 2018-05-03 14:51:49 -0700 | [diff] [blame] | 25 | RB_FOR_EACH_CONTAINER(&(wq)->waitq.tree, thread_ptr, base.qnode_rb) |
| 26 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 27 | static inline void z_waitq_init(_wait_q_t *w) |
Andy Ross | 1acd8c2 | 2018-05-03 14:51:49 -0700 | [diff] [blame] | 28 | { |
| 29 | w->waitq = (struct _priq_rb) { |
| 30 | .tree = { |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 31 | .lessthan_fn = z_priq_rb_lessthan |
Andy Ross | 1acd8c2 | 2018-05-03 14:51:49 -0700 | [diff] [blame] | 32 | } |
| 33 | }; |
| 34 | } |
| 35 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 36 | static inline struct k_thread *z_waitq_head(_wait_q_t *w) |
Andy Ross | 1acd8c2 | 2018-05-03 14:51:49 -0700 | [diff] [blame] | 37 | { |
Benoit Leforestier | 9915b4e | 2019-04-25 14:46:55 +0200 | [diff] [blame] | 38 | return (struct k_thread *)rb_get_min(&w->waitq.tree); |
Andy Ross | 1acd8c2 | 2018-05-03 14:51:49 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Andy Ross | 225c74b | 2018-06-27 11:20:50 -0700 | [diff] [blame] | 41 | #else /* !CONFIG_WAITQ_SCALABLE: */ |
Andy Ross | 1acd8c2 | 2018-05-03 14:51:49 -0700 | [diff] [blame] | 42 | |
| 43 | #define _WAIT_Q_FOR_EACH(wq, thread_ptr) \ |
| 44 | SYS_DLIST_FOR_EACH_CONTAINER(&((wq)->waitq), thread_ptr, \ |
| 45 | base.qnode_dlist) |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 46 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 47 | static inline void z_waitq_init(_wait_q_t *w) |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 48 | { |
| 49 | sys_dlist_init(&w->waitq); |
| 50 | } |
| 51 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 52 | static inline struct k_thread *z_waitq_head(_wait_q_t *w) |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 53 | { |
Benoit Leforestier | 9915b4e | 2019-04-25 14:46:55 +0200 | [diff] [blame] | 54 | return (struct k_thread *)sys_dlist_peek_head(&w->waitq); |
Andy Ross | ccf3bf7 | 2018-05-10 11:10:34 -0700 | [diff] [blame] | 55 | } |
Benjamin Walsh | fcdb0fd | 2017-01-28 16:56:18 -0500 | [diff] [blame] | 56 | |
Andy Ross | 225c74b | 2018-06-27 11:20:50 -0700 | [diff] [blame] | 57 | #endif /* !CONFIG_WAITQ_SCALABLE */ |
Andy Ross | 1acd8c2 | 2018-05-03 14:51:49 -0700 | [diff] [blame] | 58 | |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 59 | #ifdef __cplusplus |
| 60 | } |
| 61 | #endif |
| 62 | |
Flavio Ceolin | a7fffa9 | 2018-09-13 15:06:35 -0700 | [diff] [blame] | 63 | #endif /* ZEPHYR_KERNEL_INCLUDE_WAIT_Q_H_ */ |