#include "irq.h" #include "kthread.h" #include "list.h" #include "wait.h" int wake_up(struct wait_queue *wq) { struct kthread *th; uint32_t flags; disable_IRQs(flags); list_collapse(wq->thread, th) { kthreadAddThread(th); } restore_IRQs(flags); return 0; } int wait(struct wait_queue *wq) { return waitTimeout(wq, 0); } int waitTimeout(struct wait_queue *wq, unsigned long msec) { struct kthread *current, *next; uint32_t flags; int ret; disable_IRQs(flags); current = getCurrentThread(); current->state = WAITING; next = kthreadSelectNext(); kthreadUnsched(current); list_add_tail(wq->thread, current); ret = kthreadWait(current, next, msec); restore_IRQs(flags); return ret; }