1

update scheduler to arraylist

This commit is contained in:
2022-07-16 01:03:00 +02:00
parent 1f4b9d52ed
commit 499efede47
2 changed files with 36 additions and 53 deletions

View File

@ -12,31 +12,46 @@
#ifndef __Scheduler_include__
#define __Scheduler_include__
#include "devices/CGA_Stream.h"
#include "kernel/threads/Dispatch.h"
#include "kernel/threads/Thread.h"
#include "lib/Queue.h"
#include "lib/SpinLock.h"
#include "user/lib/ArrayList.h"
class Scheduler : public Dispatcher {
private:
Scheduler(const Scheduler& copy) = delete; // Verhindere Kopieren
Queue readyQueue; // auf die CPU wartende Threads
Queue blockQueue;
// Queue readyQueue; // auf die CPU wartende Threads
// Scheduler wird evt. von einer Unterbrechung vom Zeitgeber gerufen,
// bevor er initialisiert wurde
bool initialized;
bool has_idle_thread;
// NOTE: I would have to release the lock when switching threads but I don't know exactly how to do this
// in the assembly function
// SpinLock lock; // Use spinlock instead of cpu.disable_int() because it still allows preemption
// // for threads that don't use the scheduler
// NOTE: Using this instead of the Queue is a side effect, I added the ArrayList for different reasons
// but my Queue was shit so I replaced it (and didn't fix the Queue)
ArrayList<Thread*> ready_queue;
public:
Scheduler() : initialized(false) {}
Scheduler() : has_idle_thread(false) {}
void init() {
this->ready_queue.init();
}
// Scheduler initialisiert?
// Zeitgeber-Unterbrechung kommt evt. bevor der Scheduler fertig
// intiialisiert wurde!
bool isInitialized() const { return initialized; }
bool preemption_enabled() const { return has_idle_thread; }
// ruft nur der Idle-Thread (erster Thread der vom Scheduler gestartet wird)
void setInitialized() { initialized = true; }
void enable_preemption() { has_idle_thread = true; }
// Scheduler starten
void schedule();
@ -56,12 +71,8 @@ public:
// Thread umschalten; wird aus der ISR des PITs gerufen
void preempt();
// TODO: Merge this with usual block/deblock
void block();
void deblock(Thread* that);
// void block();
// void deblock(Thread* that);
};
#endif