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