Fix scheduler with sleeping task

This commit is contained in:
Mathieu Maret 2020-05-03 23:13:17 +02:00
parent b1e6bc1aab
commit 319f197fcd
2 changed files with 11 additions and 6 deletions

View File

@ -77,10 +77,13 @@ free_mem:
void kthreadDelete(struct kthread *thread)
{
uint32_t flags;
disable_IRQs(flags);
list_delete(currentThread, thread);
free((void *)thread->stackAddr);
free((void *)thread);
restore_IRQs(flags);
}
struct kthread *kthreadSelectNext()
@ -93,8 +96,7 @@ struct kthread *kthreadSelectNext()
return nextThread;
}
}
assert("Cannot find next thread\n");
return nextThread;
return currentThread;
}
struct cpu_state *kthreadSwitch(struct cpu_state *prevCpu)
@ -140,7 +142,9 @@ int kthreadYield()
restore_IRQs(flags);
return 0;
}
current->state = READY;
assert(current->state == RUNNING);
assert(next->state == READY);
current->state = READY;
currentThread = next;
currentThread->state = RUNNING;
cpu_context_switch(&current->cpuState, next->cpuState);
@ -152,10 +156,11 @@ int kthreadMsleep(unsigned long msec)
{
uint32_t flags;
disable_IRQs(flags);
struct kthread *next = kthreadSelectNext();
struct kthread *current = currentThread;
assert(current->state == RUNNING);
current->state = SLEEPING;
struct kthread *next = kthreadSelectNext();
assert(next != current);
current->state = SLEEPING;
current->jiffiesSleeping = msecs_to_jiffies(msec);
assert(next->state == READY);
currentThread = next;

View File

@ -28,7 +28,7 @@ void idleThread(void *arg)
(void)arg;
while (1) {
printIntDetails((jiffies / HZ), GREEN, BLACK, 0, VGA_HEIGHT - 1);
//kthreadYield();
kthreadYield();
}
}