1 #include <lunaix/ds/waitq.h>
2 #include <lunaix/process.h>
3 #include <lunaix/sched.h>
4 #include <lunaix/spike.h>
9 assert(current_thread);
10 // prevent race condition.
11 cpu_disable_interrupt();
13 waitq_t* current_wq = ¤t_thread->waitqueue;
14 assert(llist_empty(¤t_wq->waiters));
16 llist_append(&queue->waiters, ¤t_wq->waiters);
18 block_current_thread();
21 // In case of SIGINT-forced awaken
22 llist_delete(¤t_wq->waiters);
23 cpu_enable_interrupt();
27 pwake_one(waitq_t* queue)
29 if (llist_empty(&queue->waiters)) {
33 waitq_t* wq = list_entry(queue->waiters.next, waitq_t, waiters);
34 struct thread* thread = container_of(wq, struct thread, waitqueue);
36 assert(thread->state == PS_BLOCKED);
37 thread->state = PS_READY;
38 llist_delete(&wq->waiters);
42 pwake_all(waitq_t* queue)
44 if (llist_empty(&queue->waiters)) {
48 struct thread* thread;
50 llist_for_each(pos, n, &queue->waiters, waiters)
52 thread = container_of(pos, struct thread, waitqueue);
54 assert(thread->state == PS_BLOCKED);
55 thread->state = PS_READY;
56 llist_delete(&pos->waiters);