update demos for nice_kill
This commit is contained in:
@ -19,13 +19,7 @@ private:
|
||||
IdleThread(const Thread& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
IdleThread() {
|
||||
log << INFO << "Initialized Idle Thread with ID: " << dec << this->tid << endl;
|
||||
}
|
||||
|
||||
~IdleThread() override {
|
||||
log << ERROR << "Uninitialized Idle Thread with ID: " << dec << this->tid << endl;
|
||||
}
|
||||
IdleThread() : Thread("IdleThread") {}
|
||||
|
||||
void run() override {
|
||||
// Idle-Thread läuft, ab jetzt ist der Scheduler fertig initialisiert
|
||||
|
@ -13,7 +13,7 @@
|
||||
void print_demo_menu() {
|
||||
kout.lock();
|
||||
kout.clear();
|
||||
kout << "Demo Menu, press number to start, K to kill:\n"
|
||||
kout << "Demo Menu, press number to start, k/K to kill:\n"
|
||||
<< "1 - Text Demo\n"
|
||||
<< "2 - PCSPK Demo\n"
|
||||
<< "3 - Keyboard Demo\n"
|
||||
@ -30,10 +30,10 @@ void MainMenu::run() {
|
||||
|
||||
char input = '\0';
|
||||
unsigned int running_demo = 0;
|
||||
while (true) {
|
||||
while (running) {
|
||||
input = this->listener.waitForKeyEvent();
|
||||
|
||||
if (running_demo == 0) {
|
||||
if (input >= '0' && input <= '9') {
|
||||
switch (input) {
|
||||
case '1':
|
||||
running_demo = scheduler.ready<TextDemo>();
|
||||
@ -57,23 +57,23 @@ void MainMenu::run() {
|
||||
running_demo = scheduler.ready<PreemptiveThreadDemo>(3);
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
case '8':
|
||||
running_demo = scheduler.ready<VectorDemo>();
|
||||
break;
|
||||
case 'w':
|
||||
case '9':
|
||||
running_demo = scheduler.ready<ArrayDemo>();
|
||||
break;
|
||||
case 'e':
|
||||
case '0':
|
||||
running_demo = scheduler.ready<SmartPointerDemo>();
|
||||
break;
|
||||
}
|
||||
} else if (input == 'k') {
|
||||
scheduler.nice_kill(running_demo); // NOTE: If thread exits itself this will throw error
|
||||
print_demo_menu();
|
||||
} else if (input == 'K') {
|
||||
scheduler.kill(running_demo); // NOTE: If thread exits itself this will throw error
|
||||
running_demo = 0;
|
||||
scheduler.kill(running_demo);
|
||||
print_demo_menu();
|
||||
}
|
||||
|
||||
input = '\0';
|
||||
}
|
||||
|
||||
scheduler.exit();
|
||||
|
@ -12,13 +12,11 @@ private:
|
||||
KeyEventListener listener;
|
||||
|
||||
public:
|
||||
MainMenu() : listener(this->tid) {
|
||||
log << INFO << "MainMenu initialized with ID: " << dec << this->tid << endl;
|
||||
MainMenu() : Thread("MainMenu"), listener(this->tid) {
|
||||
kevman.subscribe(this->listener);
|
||||
}
|
||||
|
||||
~MainMenu() override {
|
||||
log << INFO << "Unitialized MainMenu" << endl;
|
||||
kevman.unsubscribe(this->listener);
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,7 @@ private:
|
||||
ArrayDemo(const ArrayDemo& copy) = delete;
|
||||
|
||||
public:
|
||||
ArrayDemo() {
|
||||
kout << "Initialized ArrayDemo" << endl;
|
||||
}
|
||||
ArrayDemo() : Thread("ArrayDemo") {}
|
||||
|
||||
void run() override;
|
||||
};
|
||||
|
@ -9,12 +9,9 @@ private:
|
||||
BlueScreenDemo(const BlueScreenDemo& copy) = delete;
|
||||
|
||||
public:
|
||||
BlueScreenDemo() {
|
||||
kout << "Initialized BlueScreenDemo" << endl;
|
||||
}
|
||||
BlueScreenDemo() : Thread("BlueScreenDemo") {}
|
||||
|
||||
void run() override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -25,9 +25,7 @@ private:
|
||||
HeapDemo(const HeapDemo& copy) = delete;
|
||||
|
||||
public:
|
||||
HeapDemo() {
|
||||
kout << "Initialized HeapDemo" << endl;
|
||||
}
|
||||
HeapDemo() : Thread("HeapDemo") {}
|
||||
|
||||
void run() override;
|
||||
};
|
||||
|
@ -24,8 +24,11 @@ void KeyboardDemo::run() {
|
||||
kout << "\nInput: ";
|
||||
kout.flush();
|
||||
|
||||
while (true) {
|
||||
while (running) {
|
||||
kout << listener.waitForKeyEvent();
|
||||
kout.flush();
|
||||
}
|
||||
|
||||
kout.unlock();
|
||||
scheduler.exit();
|
||||
}
|
||||
|
@ -22,16 +22,20 @@ private:
|
||||
KeyEventListener listener;
|
||||
|
||||
public:
|
||||
KeyboardDemo() : listener(this->tid) {
|
||||
log << INFO << "Initialized KeyboardDemo with ID: " << dec << this->tid << endl;
|
||||
KeyboardDemo() : Thread("KeyboardDemo"), listener(this->tid) {
|
||||
kevman.subscribe(this->listener);
|
||||
}
|
||||
|
||||
// Base class destructor will be called automatically
|
||||
~KeyboardDemo() override {
|
||||
log << INFO << "Uninitialized KeyboardDemo" << endl;
|
||||
if (running) {
|
||||
// NOTE: If the thread was exited nicely it can unlock before destructor,
|
||||
// but on forced kill kout has to be unlocked in the destructor.
|
||||
// This is bad since it could release the lock although some other
|
||||
// thread set it (so use nice_kill)
|
||||
kout.unlock();
|
||||
}
|
||||
kevman.unsubscribe(this->listener);
|
||||
kout.unlock();
|
||||
}
|
||||
|
||||
void run() override;
|
||||
|
@ -11,9 +11,7 @@ private:
|
||||
void (PCSPK::*melody)(void); // Allow to pass a melody to play when initializing the demo
|
||||
|
||||
public:
|
||||
PCSPKdemo(void (PCSPK::*melody)(void)) : melody(melody) {
|
||||
kout << "Initialized PCSPKdemo" << endl;
|
||||
}
|
||||
PCSPKdemo(void (PCSPK::*melody)(void)) : Thread("PCSPKdemo"), melody(melody) {}
|
||||
|
||||
~PCSPKdemo() override {
|
||||
pcspk.off();
|
||||
|
@ -3,7 +3,7 @@
|
||||
void PreemptiveLoopThread::run() {
|
||||
int cnt = 0;
|
||||
|
||||
while (true) {
|
||||
while (running) {
|
||||
// Basic synchronization by semaphore
|
||||
kout.lock();
|
||||
|
||||
@ -13,6 +13,8 @@ void PreemptiveLoopThread::run() {
|
||||
|
||||
kout.unlock();
|
||||
}
|
||||
|
||||
scheduler.exit();
|
||||
}
|
||||
|
||||
void PreemptiveThreadDemo::run() {
|
||||
|
@ -12,7 +12,7 @@ private:
|
||||
|
||||
public:
|
||||
// Gibt der Loop einen Stack und eine Id.
|
||||
PreemptiveLoopThread(int i) : id(i) {}
|
||||
PreemptiveLoopThread(int i) : Thread("LoopThread"), id(i) {}
|
||||
|
||||
// Zaehlt einen Zaehler hoch und gibt ihn auf dem Bildschirm aus.
|
||||
void run() override;
|
||||
@ -25,9 +25,7 @@ private:
|
||||
unsigned int number_of_threads;
|
||||
|
||||
public:
|
||||
PreemptiveThreadDemo(unsigned int n) : number_of_threads(n) {
|
||||
kout << "Initialized PreemptiveThreadDemo" << endl;
|
||||
}
|
||||
PreemptiveThreadDemo(unsigned int n) : Thread("PreemptiveThreadDemo"), number_of_threads(n) {}
|
||||
|
||||
// Thread-Startmethode
|
||||
void run() override;
|
||||
|
@ -8,9 +8,7 @@ private:
|
||||
SmartPointerDemo(const SmartPointerDemo& copy) = delete;
|
||||
|
||||
public:
|
||||
SmartPointerDemo() {
|
||||
kout << "Initialized SmartPointerDemo" << endl;
|
||||
}
|
||||
SmartPointerDemo() : Thread("SmartPointerDemo") {}
|
||||
|
||||
void run() override;
|
||||
};
|
||||
|
@ -19,9 +19,7 @@ private:
|
||||
TextDemo(const TextDemo& copy) = delete;
|
||||
|
||||
public:
|
||||
TextDemo() {
|
||||
log << INFO << "Initialized TextDemo" << endl;
|
||||
}
|
||||
TextDemo() : Thread("TextDemo") {}
|
||||
|
||||
void run() override;
|
||||
};
|
||||
|
@ -102,6 +102,8 @@ void VBEdemo::run() {
|
||||
drawBitmap();
|
||||
drawFonts();
|
||||
|
||||
while (running) {}
|
||||
|
||||
// selbst terminieren
|
||||
// scheduler.exit();
|
||||
scheduler.exit();
|
||||
}
|
||||
|
@ -24,9 +24,7 @@ private:
|
||||
|
||||
public:
|
||||
// Gib dem Anwendungsthread einen Stack.
|
||||
VBEdemo() {
|
||||
kout << "Initialized VBEdemo" << endl;
|
||||
}
|
||||
VBEdemo() : Thread("VBEdemo") {}
|
||||
|
||||
~VBEdemo() override {
|
||||
vesa.initTextMode();
|
||||
|
@ -10,9 +10,7 @@ private:
|
||||
VectorDemo(const VectorDemo& copy) = delete;
|
||||
|
||||
public:
|
||||
VectorDemo() {
|
||||
kout << "Initialized VectorDemo" << endl;
|
||||
}
|
||||
VectorDemo() : Thread("VectorDemo") {}
|
||||
|
||||
void run() override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user