feat: serial device interfacing
[lunaix-os.git] / lunaix-os / includes / lunaix / ds / waitq.h
index dfeb7c377893cdae489521b7c93f6cd8b7c23d29..219bf049d0340e96505cce52d715bb7befd50936 100644 (file)
@@ -2,18 +2,25 @@
 #define __LUNAIX_CODVAR_H
 
 #include <lunaix/ds/llist.h>
+#include <lunaix/sched.h>
 
 typedef struct waitq
 {
     struct llist_header waiters;
 } waitq_t;
 
-inline void
+static inline void
 waitq_init(waitq_t* waitq)
 {
     llist_init_head(&waitq->waiters);
 }
 
+static inline int
+waitq_empty(waitq_t* waitq)
+{
+    return llist_empty(&waitq->waiters);
+}
+
 void
 pwait(waitq_t* queue);
 
@@ -23,4 +30,9 @@ pwake_one(waitq_t* queue);
 void
 pwake_all(waitq_t* queue);
 
+#define wait_if(cond)                                                          \
+    while ((cond)) {                                                           \
+        sched_yieldk();                                                        \
+    }
+
 #endif /* __LUNAIX_CODVAR_H */