fix scheduler bug
This commit is contained in:
@ -21,16 +21,11 @@ void Scheduler::schedule() {
|
|||||||
|
|
||||||
/* hier muss Code eingefuegt werden */
|
/* hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
Thread* idle = new IdleThread();
|
// We need to start the idle thread first as this one sets the scheduler to initialized
|
||||||
// this->readyQueue.enqueue(idle);
|
// Other wise preemption will be blocked and nothing will happen if the first threads
|
||||||
this->ready(idle);
|
// ready() function is blocking
|
||||||
|
this->start(*(Thread*)new IdleThread()); // The idle thread set initialized to true, so preemption
|
||||||
/* Bevor diese Methode anufgerufen wird, muss zumindest der Idle-Thread
|
// only starts after this
|
||||||
* in der Queue eingefuegt worden sein.
|
|
||||||
*/
|
|
||||||
|
|
||||||
Thread& first = *(Thread*)this->readyQueue.dequeue();
|
|
||||||
this->start(first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -115,9 +110,6 @@ void Scheduler::yield() {
|
|||||||
|
|
||||||
/* hier muss Code eingefuegt werden */
|
/* hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
// Thread-Wechsel durch PIT verhindern
|
|
||||||
// cpu.disable_int ();
|
|
||||||
|
|
||||||
// When only one thread exists (IdleThread) it can't yield as the readyqueue becomes empty
|
// When only one thread exists (IdleThread) it can't yield as the readyqueue becomes empty
|
||||||
// and this is not handled anywhere else
|
// and this is not handled anywhere else
|
||||||
if (this->readyQueue.isEmpty()) {
|
if (this->readyQueue.isEmpty()) {
|
||||||
@ -125,12 +117,12 @@ void Scheduler::yield() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Thread-Wechsel durch PIT verhindern
|
||||||
|
cpu.disable_int ();
|
||||||
|
|
||||||
Thread& next = *(Thread*)this->readyQueue.dequeue();
|
Thread& next = *(Thread*)this->readyQueue.dequeue();
|
||||||
this->readyQueue.enqueue(this->get_active());
|
this->readyQueue.enqueue(this->get_active());
|
||||||
this->dispatch(next);
|
this->dispatch(next);
|
||||||
|
|
||||||
// Thread-Wechsel durch PIT jetzt wieder erlauben
|
|
||||||
// cpu.enable_int ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -142,6 +134,17 @@ void Scheduler::yield() {
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void Scheduler::preempt () {
|
void Scheduler::preempt () {
|
||||||
|
|
||||||
/* Hier muss Code eingefuegt werden */
|
/* Hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
|
if (this->readyQueue.isEmpty()) {
|
||||||
|
// Idle thread running
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thread-Wechsel durch PIT verhindern
|
||||||
|
cpu.disable_int ();
|
||||||
|
|
||||||
|
Thread& next = *(Thread*)this->readyQueue.dequeue();
|
||||||
|
this->readyQueue.enqueue(this->get_active());
|
||||||
|
this->dispatch(next);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user