remove semaphore from cga_stream
This commit is contained in:
@ -35,40 +35,28 @@ public:
|
|||||||
const CGA::color bg;
|
const CGA::color bg;
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOTE: I didn't want to use macro definitions since I don't like them,
|
constexpr fgc white = fgc(CGA::WHITE);
|
||||||
// makes it easier to change colors
|
constexpr fgc black = fgc(CGA::BLACK);
|
||||||
constexpr bgc white_b = bgc(CGA::WHITE);
|
constexpr fgc green = fgc(CGA::GREEN);
|
||||||
constexpr bgc black_b = bgc(CGA::BLACK);
|
constexpr fgc red = fgc(CGA::RED);
|
||||||
constexpr bgc green_b = bgc(CGA::GREEN);
|
constexpr fgc lgrey = fgc(CGA::LIGHT_GREY);
|
||||||
constexpr bgc red_b = bgc(CGA::RED);
|
|
||||||
constexpr bgc lgrey_b = bgc(CGA::LIGHT_GREY);
|
|
||||||
constexpr fgc white_f = fgc(CGA::WHITE);
|
|
||||||
constexpr fgc black_f = fgc(CGA::BLACK);
|
|
||||||
constexpr fgc green_f = fgc(CGA::GREEN);
|
|
||||||
constexpr fgc red_f = fgc(CGA::RED);
|
|
||||||
constexpr fgc lgrey_f = fgc(CGA::LIGHT_GREY);
|
|
||||||
|
|
||||||
class CGA_Stream : public OutStream, public CGA {
|
class CGA_Stream : public OutStream, public CGA {
|
||||||
private:
|
private:
|
||||||
CGA_Stream(CGA_Stream& copy) = delete; // Verhindere Kopieren
|
CGA_Stream(CGA_Stream& copy) = delete; // Verhindere Kopieren
|
||||||
|
|
||||||
Semaphore sem;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CGA::color color_fg;
|
CGA::color color_fg;
|
||||||
CGA::color color_bg;
|
CGA::color color_bg;
|
||||||
bool blink;
|
bool blink;
|
||||||
|
|
||||||
CGA_Stream() : sem(1), color_fg(CGA::LIGHT_GREY), color_bg(CGA::BLACK), blink(false) {
|
CGA_Stream() : color_fg(CGA::LIGHT_GREY), color_bg(CGA::BLACK), blink(false) {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methode zur Ausgabe des Pufferinhalts der Basisklasse StringBuffer.
|
// Methode zur Ausgabe des Pufferinhalts der Basisklasse StringBuffer.
|
||||||
void flush() override;
|
void flush() override;
|
||||||
|
|
||||||
void lock() { sem.p(); }
|
|
||||||
void unlock() { sem.v(); }
|
|
||||||
|
|
||||||
// Change stream color
|
// Change stream color
|
||||||
template<typename T>
|
template<typename T>
|
||||||
// requires std::derived_from<T, CGA_Stream>
|
// requires std::derived_from<T, CGA_Stream>
|
||||||
|
|||||||
@ -11,7 +11,6 @@
|
|||||||
#include "user/demo/VectorDemo.h"
|
#include "user/demo/VectorDemo.h"
|
||||||
|
|
||||||
void print_demo_menu() {
|
void print_demo_menu() {
|
||||||
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 to kill:\n"
|
||||||
<< "1 - Text Demo\n"
|
<< "1 - Text Demo\n"
|
||||||
@ -22,7 +21,6 @@ void print_demo_menu() {
|
|||||||
<< "6 - Bluescreen Demo\n"
|
<< "6 - Bluescreen Demo\n"
|
||||||
<< "7 - Preemption Demo\n"
|
<< "7 - Preemption Demo\n"
|
||||||
<< endl;
|
<< endl;
|
||||||
kout.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::run() {
|
void MainMenu::run() {
|
||||||
|
|||||||
@ -5,7 +5,6 @@ void ArrayDemo::run() {
|
|||||||
bse::Array<int, 10> arr2 {};
|
bse::Array<int, 10> arr2 {};
|
||||||
bse::Array<Thread*, 10> arr3 {};
|
bse::Array<Thread*, 10> arr3 {};
|
||||||
|
|
||||||
kout.lock();
|
|
||||||
kout.clear();
|
kout.clear();
|
||||||
|
|
||||||
kout << "Adding..." << endl;
|
kout << "Adding..." << endl;
|
||||||
@ -36,6 +35,5 @@ void ArrayDemo::run() {
|
|||||||
|
|
||||||
// arr1.swap(arr3); // Not possible as type/size has to match
|
// arr1.swap(arr3); // Not possible as type/size has to match
|
||||||
|
|
||||||
kout.unlock();
|
|
||||||
scheduler.exit();
|
scheduler.exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,6 @@
|
|||||||
#include "user/demo/HeapDemo.h"
|
#include "user/demo/HeapDemo.h"
|
||||||
|
|
||||||
void HeapDemo::run() {
|
void HeapDemo::run() {
|
||||||
kout.lock();
|
|
||||||
kout.clear();
|
kout.clear();
|
||||||
kout << "HEAP_DEMO ===================================================================" << endl;
|
kout << "HEAP_DEMO ===================================================================" << endl;
|
||||||
|
|
||||||
@ -73,6 +72,5 @@ void HeapDemo::run() {
|
|||||||
|
|
||||||
kout << "HEAP_DEMO END ===============================================================" << endl;
|
kout << "HEAP_DEMO END ===============================================================" << endl;
|
||||||
|
|
||||||
kout.unlock();
|
|
||||||
scheduler.exit();
|
scheduler.exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,21 +1,19 @@
|
|||||||
#include "user/demo/PreemptiveThreadDemo.h"
|
#include "user/demo/PreemptiveThreadDemo.h"
|
||||||
|
|
||||||
|
Semaphore PreemptiveLoopThread::sem(1);
|
||||||
|
|
||||||
void PreemptiveLoopThread::run() {
|
void PreemptiveLoopThread::run() {
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Basic synchronization by semaphore
|
// Basic synchronization by semaphore
|
||||||
// NOTE: I placed the semaphore inside the CGA_Stream so multiple demos can synchronize, not
|
sem.p();
|
||||||
// only this one. This is optional so disruptions can still occur because of preemption
|
|
||||||
// (I only use this for the user output (demos), anywhere else could become problematic
|
|
||||||
// quickly...)
|
|
||||||
kout.lock();
|
|
||||||
|
|
||||||
// Saving + restoring kout position doesn't help much as preemption still occurs
|
// Saving + restoring kout position doesn't help much as preemption still occurs
|
||||||
kout.setpos(55, this->id);
|
kout.setpos(55, this->id);
|
||||||
kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
|
kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
|
||||||
|
|
||||||
kout.unlock();
|
sem.v();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
class PreemptiveLoopThread : public Thread {
|
class PreemptiveLoopThread : public Thread {
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
// Semaphore* sem;
|
static Semaphore sem;
|
||||||
|
|
||||||
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren
|
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
#include "user/lib/mem/UniquePointer.h"
|
#include "user/lib/mem/UniquePointer.h"
|
||||||
|
|
||||||
void SmartPointerDemo::run() {
|
void SmartPointerDemo::run() {
|
||||||
kout.lock();
|
|
||||||
kout.clear();
|
kout.clear();
|
||||||
|
|
||||||
kout << "Output is written to log to be able to trace memory allocations/deallocations" << endl;
|
kout << "Output is written to log to be able to trace memory allocations/deallocations" << endl;
|
||||||
@ -119,6 +118,5 @@ void SmartPointerDemo::run() {
|
|||||||
}
|
}
|
||||||
log << INFO << "Should be deleted by now..." << endl;
|
log << INFO << "Should be deleted by now..." << endl;
|
||||||
|
|
||||||
kout.unlock();
|
|
||||||
scheduler.exit();
|
scheduler.exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,15 +14,14 @@ void TextDemo::run() {
|
|||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
kout.lock();
|
|
||||||
kout.clear();
|
kout.clear();
|
||||||
kout << "TextDemo\n"
|
kout << "TextDemo\n"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
kout << "Attribut (GREEN on WHITE): "
|
kout << "Attribut (GREEN on WHITE): "
|
||||||
<< white_b << green_f << "GREEN on WHITE" << endl
|
<< bgc(CGA::WHITE) << green << "GREEN on WHITE" << endl
|
||||||
<< "Attribut (WHITE on BLACK): "
|
<< "Attribut (WHITE on BLACK): "
|
||||||
<< black_b << white_f << "WHITE on BLACK" << endl;
|
<< bgc(CGA::BLACK) << white << "WHITE on BLACK" << endl;
|
||||||
kout << endl;
|
kout << endl;
|
||||||
|
|
||||||
kout << "Test der Zahlenausgabefunktion:" << endl
|
kout << "Test der Zahlenausgabefunktion:" << endl
|
||||||
@ -37,7 +36,6 @@ void TextDemo::run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kout << endl;
|
kout << endl;
|
||||||
kout.unlock();
|
|
||||||
|
|
||||||
scheduler.exit();
|
scheduler.exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,6 @@ void print(bse::Vector<int> list) {
|
|||||||
void VectorDemo::run() {
|
void VectorDemo::run() {
|
||||||
bse::Vector<int> list;
|
bse::Vector<int> list;
|
||||||
|
|
||||||
kout.lock();
|
|
||||||
kout.clear();
|
kout.clear();
|
||||||
kout << "Initial list size: " << dec << list.size() << endl;
|
kout << "Initial list size: " << dec << list.size() << endl;
|
||||||
|
|
||||||
@ -103,6 +102,5 @@ void VectorDemo::run() {
|
|||||||
kout << "List contains element: " << dec << i << endl;
|
kout << "List contains element: " << dec << i << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
kout.unlock();
|
|
||||||
scheduler.exit();
|
scheduler.exit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user