Essentially I have three process running, one prints out the process tree before sleeping for a second, and then repeating. Another continuously sets a condition variable to true and then calls the wakeup function. The final resets the condition variable before calling the wait_event function. That process also outputs a little test message every loop.
When I let it run, after a few seconds the output from the 3rd process stops. Sometimes the output from the debugging process, the first one mentioned, stops too. The two functions are shown below:
Code: Select all
void wait_event(sleep_queue_t* waitqueue, uint32_t* condition)
{
if (!waitqueue || !condition || !waitqueue->queue) // Passing bad pointers
return;
while (!*condition)
{
spin_lock(&waitqueue->lock);
list_append_node(waitqueue->queue, &currProc->sleepNode, currProc);
IRQ_OFF;
spin_unlock(&waitqueue->lock);
proc_setState(currProc, TASK_UNINTERRUPTIBLE);
if (!*condition) // If we get woken up between releasing the lock and the process state change
yield();
proc_setState(currProc, TASK_RUNNING);
IRQ_RES;
}
}
void wakeup_queue(sleep_queue_t* waitqueue)
{
if (!waitqueue || !waitqueue->queue)
return;
spin_lock(&waitqueue->lock);
list_node_t* wakeNode = list_dequeue(waitqueue->queue);
while (wakeNode)
{
process_t* wakeProc = (process_t*)wakeNode->data;
proc_setState(wakeProc, TASK_RUNNING);
if (!list_find(waitqueue->queue, wakeProc))
{
sched_queueRunnable(wakeProc);
}
wakeNode = list_dequeue(waitqueue->queue);
}
spin_unlock(&waitqueue->lock);
}