X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/5ea8e2ba737f903db81d49b56778e883634512a5..8fce4520de1f257819b16f9253fa28dcdae743f4:/lunaix-os/kernel/ds/waitq.c?ds=inline diff --git a/lunaix-os/kernel/ds/waitq.c b/lunaix-os/kernel/ds/waitq.c index 5241a4e..caed3bc 100644 --- a/lunaix-os/kernel/ds/waitq.c +++ b/lunaix-os/kernel/ds/waitq.c @@ -1,19 +1,23 @@ #include #include -#include #include void pwait(waitq_t* queue) { + assert(__current); + // prevent race condition. + cpu_disable_interrupt(); + waitq_t* current_wq = &__current->waitqueue; assert(llist_empty(¤t_wq->waiters)); llist_append(&queue->waiters, ¤t_wq->waiters); - // FIXME centralize the state change. - __current->state = PS_BLOCKED; + block_current(); sched_yieldk(); + + cpu_enable_interrupt(); } void @@ -44,6 +48,7 @@ pwake_all(waitq_t* queue) { proc = container_of(pos, struct proc_info, waitqueue); + assert(proc->state == PS_BLOCKED); proc->state = PS_READY; llist_delete(&pos->waiters); }