Fix scheduler with sleeping task
This commit is contained in:
parent
b1e6bc1aab
commit
319f197fcd
@ -77,10 +77,13 @@ free_mem:
|
|||||||
|
|
||||||
void kthreadDelete(struct kthread *thread)
|
void kthreadDelete(struct kthread *thread)
|
||||||
{
|
{
|
||||||
|
uint32_t flags;
|
||||||
|
disable_IRQs(flags);
|
||||||
list_delete(currentThread, thread);
|
list_delete(currentThread, thread);
|
||||||
|
|
||||||
free((void *)thread->stackAddr);
|
free((void *)thread->stackAddr);
|
||||||
free((void *)thread);
|
free((void *)thread);
|
||||||
|
restore_IRQs(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct kthread *kthreadSelectNext()
|
struct kthread *kthreadSelectNext()
|
||||||
@ -93,8 +96,7 @@ struct kthread *kthreadSelectNext()
|
|||||||
return nextThread;
|
return nextThread;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert("Cannot find next thread\n");
|
return currentThread;
|
||||||
return nextThread;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cpu_state *kthreadSwitch(struct cpu_state *prevCpu)
|
struct cpu_state *kthreadSwitch(struct cpu_state *prevCpu)
|
||||||
@ -140,6 +142,8 @@ int kthreadYield()
|
|||||||
restore_IRQs(flags);
|
restore_IRQs(flags);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
assert(current->state == RUNNING);
|
||||||
|
assert(next->state == READY);
|
||||||
current->state = READY;
|
current->state = READY;
|
||||||
currentThread = next;
|
currentThread = next;
|
||||||
currentThread->state = RUNNING;
|
currentThread->state = RUNNING;
|
||||||
@ -152,10 +156,11 @@ int kthreadMsleep(unsigned long msec)
|
|||||||
{
|
{
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
disable_IRQs(flags);
|
disable_IRQs(flags);
|
||||||
struct kthread *next = kthreadSelectNext();
|
|
||||||
struct kthread *current = currentThread;
|
struct kthread *current = currentThread;
|
||||||
assert(next != current);
|
assert(current->state == RUNNING);
|
||||||
current->state = SLEEPING;
|
current->state = SLEEPING;
|
||||||
|
struct kthread *next = kthreadSelectNext();
|
||||||
|
assert(next != current);
|
||||||
current->jiffiesSleeping = msecs_to_jiffies(msec);
|
current->jiffiesSleeping = msecs_to_jiffies(msec);
|
||||||
assert(next->state == READY);
|
assert(next->state == READY);
|
||||||
currentThread = next;
|
currentThread = next;
|
||||||
|
@ -28,7 +28,7 @@ void idleThread(void *arg)
|
|||||||
(void)arg;
|
(void)arg;
|
||||||
while (1) {
|
while (1) {
|
||||||
printIntDetails((jiffies / HZ), GREEN, BLACK, 0, VGA_HEIGHT - 1);
|
printIntDetails((jiffies / HZ), GREEN, BLACK, 0, VGA_HEIGHT - 1);
|
||||||
//kthreadYield();
|
kthreadYield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user