2 * Copyright (c) 2015, Linaro Limited
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
27 #ifndef KERNEL_WAIT_QUEUE_H
28 #define KERNEL_WAIT_QUEUE_H
30 #include <types_ext.h>
31 #include <sys/queue.h>
33 struct wait_queue_elem;
34 SLIST_HEAD(wait_queue, wait_queue_elem);
36 #define WAIT_QUEUE_INITIALIZER { .slh_first = NULL }
39 struct wait_queue_elem {
43 SLIST_ENTRY(wait_queue_elem) link;
47 * Initializes a wait queue
49 void wq_init(struct wait_queue *wq);
52 * Initializes a wait queue element and adds it to the wait queue. This
53 * function is supposed to be called before the lock that protects the
54 * resource we need to wait for is released.
56 * One call to this function must be followed by one call to wq_wait_final()
57 * on the same wait queue element.
59 void wq_wait_init_condvar(struct wait_queue *wq, struct wait_queue_elem *wqe,
62 static inline void wq_wait_init(struct wait_queue *wq,
63 struct wait_queue_elem *wqe)
65 wq_wait_init_condvar(wq, wqe, NULL);
68 /* Waits for the wait queue element to the awakened. */
69 void wq_wait_final(struct wait_queue *wq, struct wait_queue_elem *wqe,
70 const void *sync_obj, int owner, const char *fname,
73 /* Wakes up the first wait queue element in the wait queue, if there is one */
74 void wq_wake_one(struct wait_queue *wq, const void *sync_obj,
75 const char *fname, int lineno);
77 /* Returns true if the wait queue doesn't contain any elements */
78 bool wq_is_empty(struct wait_queue *wq);
80 void wq_promote_condvar(struct wait_queue *wq, struct condvar *cv,
81 bool only_one, const void *sync_obj, const char *fname,
83 bool wq_have_condvar(struct wait_queue *wq, struct condvar *cv);
85 #endif /*KERNEL_WAIT_QUEUE_H*/