1

merged cleanup

This commit is contained in:
2022-07-24 21:12:31 +02:00
parent 5ff3d72bfd
commit 6481bae5f6
92 changed files with 663 additions and 755 deletions

View File

@ -8,8 +8,8 @@
* Autor: Michael, Schoettner, HHU, 13.8.2016 *
*****************************************************************************/
#ifndef __IdleThread_include__
#define __IdleThread_include__
#ifndef IdleThread_include__
#define IdleThread_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
@ -20,10 +20,10 @@ public:
IdleThread() : Thread("IdleThread") {}
/*[[noreturn]]*/ void run() override {
[[noreturn]] void run() override {
// Idle-Thread läuft, ab jetzt ist der Scheduler fertig initialisiert
log.info() << "IdleThread enabled preemption" << endl;
scheduler.enable_preemption(this->tid);
scheduler.enable_preemption(tid);
if (!scheduler.preemption_enabled()) {
log.error() << "Preemption disabled" << endl;
}

View File

@ -9,8 +9,8 @@
* Autor: Michael, Schoettner, HHU, 22.8.2016 *
*****************************************************************************/
#ifndef __Scheduler_include__
#define __Scheduler_include__
#ifndef Scheduler_include__
#define Scheduler_include__
#include "kernel/threads/Thread.h"
#include "user/lib/Logger.h"
@ -33,8 +33,8 @@ private:
unsigned int idle_tid = 0U;
// Roughly the old dispatcher functionality
/*[[noreturn]]*/ void start(bse::vector<bse::unique_ptr<Thread>>::iterator next); // Start next without prev
/*[[noreturn]]*/ void switch_to(Thread* prev_raw, bse::vector<bse::unique_ptr<Thread>>::iterator next); // Switch from prev to next
void start(bse::vector<bse::unique_ptr<Thread>>::iterator next); // Start next without prev
void switch_to(Thread* prev_raw, bse::vector<bse::unique_ptr<Thread>>::iterator next); // Switch from prev to next
// Kann nur vom Idle-Thread aufgerufen werden (erster Thread der vom Scheduler gestartet wird)
void enable_preemption(unsigned int tid) { idle_tid = tid; }
@ -63,7 +63,7 @@ public:
bool preemption_enabled() const { return idle_tid != 0U; }
// Scheduler starten
/*[[noreturn]]*/ void schedule();
void schedule();
// Helper that directly constructs the thread, then readys it
template<typename T, typename... Args>
@ -80,7 +80,7 @@ public:
// NOTE: When a thread exits itself it will disappear...
// Maybe put exited threads in an exited queue?
// Then they would have to be acquired from there to exit...
/* [[noreturn]] */ void exit(); // Returns on error because we don't have exceptions
void exit(); // Returns on error because we don't have exceptions
// Thread mit 'Gewalt' terminieren
void kill(unsigned int tid, bse::unique_ptr<Thread>* ptr);
@ -94,13 +94,13 @@ public:
void nice_kill(unsigned int tid) { nice_kill(tid, nullptr); }
// CPU freiwillig abgeben und Auswahl des naechsten Threads
/* [[noreturn]] */ void yield(); // Returns when only the idle thread runs
void yield(); // Returns when only the idle thread runs
// Thread umschalten; wird aus der ISR des PITs gerufen
/* [[noreturn]] */ void preempt(); // Returns when only the idle thread runs
void preempt(); // Returns when only the idle thread runs
// Blocks current thread (move to block_queue)
/* [[noreturn]] */ void block(); // Returns on error because we don't have exceptions
void block(); // Returns on error because we don't have exceptions
// Deblock by tid (move to ready_queue)
void deblock(unsigned int tid);

View File

@ -56,20 +56,20 @@ void Thread_init(unsigned int* esp, unsigned int* stack, void (*kickoff)(Thread*
// wird, sie darf also nicht terminieren, sonst kracht's.
// I thought this syntax was a bit clearer than decrementing a pointer
stack[-1] = (unsigned int)object;
stack[-1] = reinterpret_cast<unsigned int>(object);
stack[-2] = 0x131155U;
stack[-3] = (unsigned int)kickoff;
stack[-3] = reinterpret_cast<unsigned int>(kickoff);
stack[-4] = 0; // EAX
stack[-5] = 0; // ECX
stack[-6] = 0; // EDX
stack[-7] = 0; // EBX
stack[-8] = (unsigned int)&stack[-3]; // ESP
stack[-8] = reinterpret_cast<unsigned int>(&stack[-3]); // ESP
stack[-9] = 0; // EBP
stack[-10] = 0; // ESI
stack[-11] = 0; // EDI
stack[-12] = 0x200U;
*esp = (unsigned int)&stack[-12];
*esp = reinterpret_cast<unsigned int>(&stack[-12]);
}
/*****************************************************************************
@ -98,7 +98,7 @@ void Thread_init(unsigned int* esp, unsigned int* stack, void (*kickoff)(Thread*
* stack Stack für die neue Koroutine *
*****************************************************************************/
Thread::Thread(char* name) : stack(new unsigned int[1024]), esp(0), log(name), name(name), tid(ThreadCnt++) {
log.info() << "Initialized thread with ID: " << this->tid << " (" << name << ")" << endl;
log.info() << "Initialized thread with ID: " << tid << " (" << name << ")" << endl;
Thread_init(&esp, &stack[1024], kickoff, this); // Stack grows from top to bottom
}
@ -124,5 +124,5 @@ void Thread::start() const {
/* hier muss Code eingefügt werden */
Thread_start(this->esp);
Thread_start(esp);
}

View File

@ -7,9 +7,9 @@
* Thread-Objekte werden vom Scheduler in einer verketteten *
* Liste 'readylist' verwaltet. *
* *
* Im Konstruktor wird der initialie Kontext des Threads *
* Im Konstruktor wird der initialie Kontext des Threads *
* eingerichtet. Mit 'start' wird ein Thread aktiviert. *
* Die CPU sollte mit 'yield' freiwillig abgegeben werden. *
* Die CPU sollte mit 'yield' freiwillig abgegeben werden. *
* Um bei einem Threadwechsel den Kontext sichern zu *
* koennen, enthaelt jedes Threadobjekt eine Struktur *
* ThreadState, in dem die Werte der nicht-fluechtigen *
@ -25,8 +25,8 @@
* Autor: Michael, Schoettner, HHU, 16.12.2016 *
*****************************************************************************/
#ifndef __Thread_include__
#define __Thread_include__
#ifndef Thread_include__
#define Thread_include__
#include "user/lib/Logger.h"
@ -49,21 +49,21 @@ public:
Thread(const Thread& copy) = delete; // Verhindere Kopieren
virtual ~Thread() {
log.info() << "Uninitialized thread, ID: " << dec << this->tid << " (" << name << ")" << endl;
delete[] this->stack;
log.info() << "Uninitialized thread, ID: " << dec << tid << " (" << name << ")" << endl;
delete[] stack;
}
// Thread aktivieren
/*[[noreturn]]*/ void start() const;
void start() const;
// Umschalten auf Thread 'next'
/*[[noreturn]]*/ void switchTo(Thread& next);
void switchTo(Thread& next);
// Ask thread to terminate itself
void suicide() { running = false; }
// Methode des Threads, muss in Sub-Klasse implementiert werden
[[noreturn]] virtual void run() = 0;
virtual void run() = 0;
};
#endif