1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2015, Linaro Limited 4 */ 5 #ifndef __KERNEL_WAIT_QUEUE_H 6 #define __KERNEL_WAIT_QUEUE_H 7 8 #include <tee_api_types.h> 9 #include <types_ext.h> 10 #include <sys/queue.h> 11 12 struct wait_queue_elem; 13 SLIST_HEAD(wait_queue, wait_queue_elem); 14 15 #define WAIT_QUEUE_INITIALIZER { .slh_first = NULL } 16 17 struct condvar; 18 struct wait_queue_elem { 19 short handle; 20 bool done; 21 bool wait_read; 22 struct condvar *cv; 23 SLIST_ENTRY(wait_queue_elem) link; 24 }; 25 26 /* 27 * Initializes a wait queue 28 */ 29 void wq_init(struct wait_queue *wq); 30 31 /* 32 * Initializes a wait queue element and adds it to the wait queue. This 33 * function is supposed to be called before the lock that protects the 34 * resource we need to wait for is released. 35 * 36 * One call to this function must be followed by one call to wq_wait_final() 37 * on the same wait queue element. 38 */ 39 void wq_wait_init_condvar(struct wait_queue *wq, struct wait_queue_elem *wqe, 40 struct condvar *cv, bool wait_read); 41 42 static inline void wq_wait_init(struct wait_queue *wq, 43 struct wait_queue_elem *wqe, bool wait_read) 44 { 45 wq_wait_init_condvar(wq, wqe, NULL, wait_read); 46 } 47 48 /* Waits for the wait queue element to be awakened or timed out */ 49 TEE_Result wq_wait_final(struct wait_queue *wq, struct wait_queue_elem *wqe, 50 uint32_t timeout_ms, const void *sync_obj, 51 const char *fname, int lineno); 52 53 /* Wakes up the first wait queue element in the wait queue, if there is one */ 54 void wq_wake_next(struct wait_queue *wq, const void *sync_obj, 55 const char *fname, int lineno); 56 57 /* Returns true if the wait queue doesn't contain any elements */ 58 bool wq_is_empty(struct wait_queue *wq); 59 60 void wq_promote_condvar(struct wait_queue *wq, struct condvar *cv, 61 bool only_one, const void *sync_obj, const char *fname, 62 int lineno); 63 bool wq_have_condvar(struct wait_queue *wq, struct condvar *cv); 64 65 #endif /*__KERNEL_WAIT_QUEUE_H*/ 66 67