1

remove semaphore from cga_stream

This commit is contained in:
2022-07-22 02:56:14 +02:00
parent 3540604ec7
commit 8612587e65
9 changed files with 13 additions and 39 deletions

View File

@ -35,40 +35,28 @@ public:
const CGA::color bg;
};
// NOTE: I didn't want to use macro definitions since I don't like them,
// makes it easier to change colors
constexpr bgc white_b = bgc(CGA::WHITE);
constexpr bgc black_b = bgc(CGA::BLACK);
constexpr bgc green_b = bgc(CGA::GREEN);
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);
constexpr fgc white = fgc(CGA::WHITE);
constexpr fgc black = fgc(CGA::BLACK);
constexpr fgc green = fgc(CGA::GREEN);
constexpr fgc red = fgc(CGA::RED);
constexpr fgc lgrey = fgc(CGA::LIGHT_GREY);
class CGA_Stream : public OutStream, public CGA {
private:
CGA_Stream(CGA_Stream& copy) = delete; // Verhindere Kopieren
Semaphore sem;
public:
CGA::color color_fg;
CGA::color color_bg;
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();
}
// Methode zur Ausgabe des Pufferinhalts der Basisklasse StringBuffer.
void flush() override;
void lock() { sem.p(); }
void unlock() { sem.v(); }
// Change stream color
template<typename T>
// requires std::derived_from<T, CGA_Stream>

View File

@ -11,7 +11,6 @@
#include "user/demo/VectorDemo.h"
void print_demo_menu() {
kout.lock();
kout.clear();
kout << "Demo Menu, press number to start, K to kill:\n"
<< "1 - Text Demo\n"
@ -22,7 +21,6 @@ void print_demo_menu() {
<< "6 - Bluescreen Demo\n"
<< "7 - Preemption Demo\n"
<< endl;
kout.unlock();
}
void MainMenu::run() {

View File

@ -5,7 +5,6 @@ void ArrayDemo::run() {
bse::Array<int, 10> arr2 {};
bse::Array<Thread*, 10> arr3 {};
kout.lock();
kout.clear();
kout << "Adding..." << endl;
@ -36,6 +35,5 @@ void ArrayDemo::run() {
// arr1.swap(arr3); // Not possible as type/size has to match
kout.unlock();
scheduler.exit();
}

View File

@ -11,7 +11,6 @@
#include "user/demo/HeapDemo.h"
void HeapDemo::run() {
kout.lock();
kout.clear();
kout << "HEAP_DEMO ===================================================================" << endl;
@ -73,6 +72,5 @@ void HeapDemo::run() {
kout << "HEAP_DEMO END ===============================================================" << endl;
kout.unlock();
scheduler.exit();
}

View File

@ -1,21 +1,19 @@
#include "user/demo/PreemptiveThreadDemo.h"
Semaphore PreemptiveLoopThread::sem(1);
void PreemptiveLoopThread::run() {
int cnt = 0;
while (true) {
// Basic synchronization by semaphore
// NOTE: I placed the semaphore inside the CGA_Stream so multiple demos can synchronize, not
// 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();
sem.p();
// Saving + restoring kout position doesn't help much as preemption still occurs
kout.setpos(55, this->id);
kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
kout.unlock();
sem.v();
}
}

View File

@ -8,7 +8,7 @@
class PreemptiveLoopThread : public Thread {
private:
int id;
// Semaphore* sem;
static Semaphore sem;
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren

View File

@ -4,7 +4,6 @@
#include "user/lib/mem/UniquePointer.h"
void SmartPointerDemo::run() {
kout.lock();
kout.clear();
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;
kout.unlock();
scheduler.exit();
}

View File

@ -14,15 +14,14 @@ void TextDemo::run() {
/* Hier muess Code eingefuegt werden */
kout.lock();
kout.clear();
kout << "TextDemo\n"
<< endl;
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): "
<< black_b << white_f << "WHITE on BLACK" << endl;
<< bgc(CGA::BLACK) << white << "WHITE on BLACK" << endl;
kout << endl;
kout << "Test der Zahlenausgabefunktion:" << endl
@ -37,7 +36,6 @@ void TextDemo::run() {
}
kout << endl;
kout.unlock();
scheduler.exit();
}

View File

@ -11,7 +11,6 @@ void print(bse::Vector<int> list) {
void VectorDemo::run() {
bse::Vector<int> list;
kout.lock();
kout.clear();
kout << "Initial list size: " << dec << list.size() << endl;
@ -103,6 +102,5 @@ void VectorDemo::run() {
kout << "List contains element: " << dec << i << endl;
}
kout.unlock();
scheduler.exit();
}