diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c index 049edf7..284a519 100644 --- a/src/sys/kernel/sched.c +++ b/src/sys/kernel/sched.c @@ -131,13 +131,33 @@ nextID++; /* Print out information on scheduler */ - kprintf("sched0 solar 0.2.1 - Address: [0x%X]\n", prioQStart); + kprintf("sched0 - Address: [0x%X]\n", taskList); /* Return so we know everything went well */ return(0x0); } +/* + * A function which deletes a task's structure + * redoing all the necessary links. + */ + +static void +schedCoreDeleteTask(kTask_t *tmpTask) +{ + if (tmpTask->prev) + tmpTask->prev->next = tmpTask->next; + if (tmpTask->next) + tmpTask->next->prev = tmpTask->prev; + if (tmpTask == prioLevels[tmpTask->nice]->end) + prioLevels[tmpTask->nice]->end = tmpTask->prev; + + kfree(tmpTask->oInfo.cwd); + kfree(tmpTask); +} + + void sched() { @@ -157,17 +177,14 @@ if (tmpTask->state > 0x0) { _current = tmpTask; break; + } else if (tmpTask->state == DEAD) { + if (tmpTask == _current) + kpanic("Error: sched() - deleting current task"); + if (tmpTask == taskList) + kpanic("Error: sched() - deleting the first task"); + schedCoreDeleteTask(tmpTask); + goto schedStart; } -/* - else if (tmpTask->state == DEAD) { - if (tmpTask == _current) - kpanic("unhandled situation"); - if (schedDeleteTask(tmpTask->id) != 0x0) { - kpanic("Error: schedDeleteTask");; - } - goto schedStart; - } -*/ } /* Finished all the tasks, restarting the list */ @@ -196,7 +213,7 @@ } -kTask_t * +kTask_t* schedNewTask() { kTask_t *tmpTask = (kTask_t *)kmalloc(sizeof(kTask_t)); @@ -207,7 +224,7 @@ } //spinLock(&schedTaskSpinLock); - + /* Filling in tasks attrs */ tmpTask->usedMath = 0x0; tmpTask->id = ++nextID; @@ -244,39 +261,31 @@ */ int -schedDeleteTask(uInt32 id) { - kTask_t *tmpTask = 0x0; - - /* Checking each task from the prio queue */ - for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { - if (tmpTask->id == id) { - if (_current == tmpTask) - kpanic("you can not delete yourself!!!\n"); - if (tmpTask == taskList) - kpanic("Whoa"); - if (tmpTask->prev) - tmpTask->prev->next = tmpTask->next; - if (tmpTask->next) - tmpTask->next->prev = tmpTask->prev; - kfree(tmpTask->oInfo.cwd); - kfree(tmpTask); - return(0x0); - } - } - return(0x1); - } +schedDeleteTask(uInt32 id) +{ + kTask_t *tmpTask = 0x0; + + /* Checking each task from the prio queue */ + for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->id == id) { + schedCoreDeleteTask(tmpTask); + return(0x0); + } + } + return(0x1); +} kTask_t * schedFindTask(uInt32 id) { kTask_t *tmpTask = 0x0; - + for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { if (tmpTask->id == id) return(tmpTask); } - + return(0x0); } @@ -311,8 +320,8 @@ ************************************************************************/ void schedYield() { - sched(); - } + sched(); +} /************************************************************************ @@ -324,15 +333,18 @@ ************************************************************************/ int sched_setStatus(pidType pid,tState state) { - kTask_t *tmpTask = schedFindTask(pid); - if (tmpTask == 0x0) - return(0x1); - tmpTask->state = state; - return(0x0); - } + kTask_t *tmpTask = schedFindTask(pid); + if (tmpTask == 0x0) + return(0x1); + tmpTask->state = state; + return(0x0); +} /*** $Log$ + Revision 1.20 2004/07/25 06:04:00 reddawg + Last of my fixes for the morning + Revision 1.19 2004/07/24 15:12:56 reddawg Now I'm current