Merge branch 'master' into prog-loader
[lunaix-os.git] / lunaix-os / includes / lunaix / ds / waitq.h
1 #ifndef __LUNAIX_CODVAR_H
2 #define __LUNAIX_CODVAR_H
3
4 #include <lunaix/ds/llist.h>
5 #include <lunaix/sched.h>
6
7 typedef struct waitq
8 {
9     struct llist_header waiters;
10 } waitq_t;
11
12 static inline void
13 waitq_init(waitq_t* waitq)
14 {
15     llist_init_head(&waitq->waiters);
16 }
17
18 static inline int
19 waitq_empty(waitq_t* waitq)
20 {
21     return llist_empty(&waitq->waiters);
22 }
23
24 void
25 pwait(waitq_t* queue);
26
27 void
28 pwake_one(waitq_t* queue);
29
30 void
31 pwake_all(waitq_t* queue);
32
33 #define wait_if(cond)                                                          \
34     while ((cond)) {                                                           \
35         sched_yieldk();                                                        \
36     }
37
38 #endif /* __LUNAIX_CODVAR_H */