return(ret_val);
}
-static void _unq(struct task_queue **q, task_t *t)
+static int _unq(struct task_queue **q, task_t *t)
{
+ int ret_val;
+
+ ret_val = -ENOENT;
+
while(*q) {
if((*q)->data == t) {
struct task_queue *freeme;
*q = freeme->next;
kfree(freeme);
+ ret_val = 0;
break;
}
q = &((*q)->next);
}
- return;
+ return(ret_val);
}
void sched_tick(void)
cur_task = task_get_current();
- if(cur_task) {
+ /* skip all this if the task is exitting */
+ if(cur_task && cur_task->t_state != TASK_STATE_EXIT) {
/* check if running task has not used up it's quantum yet */
if(cur_task->t_rslice) {
cur_task->t_rslice--;
cur_task->t_state = TASK_STATE_READY;
/* put the task back on the ready queue */
- _nq(&_readyq, cur_task);
+ _nq(&_readyq, cur_task);
}
/* get the next task from the ready queue */
return(ret_val);
}
+int sched_dequeue(task_t *t)
+{
+ int ret_val;
+
+ ret_val = -EINVAL;
+
+ if(t) {
+ /* remove the task from the ready queue */
+ ret_val = _unq(&_readyq, t);
+
+ /*
+ * Attempt to remove the task from the wait queue
+ * if it wasn't on the ready queue.
+ */
+ if(ret_val < 0) {
+ ret_val = _unq(&_waitq, t);
+ }
+ }
+
+ return(ret_val);
+}
+
int sched_signal(pid_t pid)
{
task_t *cur_task;
--- /dev/null
+#ifndef __CORE_SCHED_H
+#define __CORE_SCHED_H
+
+#include <config.h>
+
+void sched_tick(void);
+void sched_wait(pid_t);
+int sched_enqueue(task_t*);
+int sched_dequeue(task_t*);
+int sched_signal(pid_t);
+
+#endif /* __CORE_SCHED_H */