#include <lunaix/ds/waitq.h>
#include <lunaix/process.h>
-#include <lunaix/sched.h>
#include <lunaix/spike.h>
void
pwait(waitq_t* queue)
{
+ // 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
{
proc = container_of(pos, struct proc_info, waitqueue);
+ assert(proc->state == PS_BLOCKED);
proc->state = PS_READY;
llist_delete(&pos->waiters);
}