1

add a shnitton of loggers

This commit is contained in:
2022-07-16 03:30:20 +02:00
parent 60d746af11
commit 2f7a2a219b
25 changed files with 177 additions and 173 deletions

View File

@ -7,13 +7,13 @@ void ArrayListDemo::run() {
for (unsigned int i = 0; i < 5; ++i) {
this->list.insert(i);
}
this->list.print();
this->list.print(kout);
kout << "Removing all elements from the front" << endl;
for (unsigned int i = 0; i < 5; ++i) {
this->list.remove_first();
}
this->list.print();
this->list.print(kout);
// ============================================================
@ -22,37 +22,37 @@ void ArrayListDemo::run() {
kout << "Add " << dec << i << endl;
this->list.insert(i);
}
this->list.print();
this->list.print(kout);
kout << "Removing all elements from the back" << endl;
for (unsigned int i = 0; i < 10; ++i) {
this->list.remove_last();
}
this->list.print();
this->list.print(kout);
// ============================================================
for (unsigned int i = 0; i < 5; ++i) {
this->list.insert(i);
}
this->list.print();
this->list.print(kout);
kout << "Adding inside the list (at idx 0, 2, 5)" << endl;
this->list.insert_at(10, 0);
this->list.insert_at(10, 2);
this->list.insert_at(10, 5);
this->list.print();
this->list.print(kout);
kout << "Removing inside the list (at idx 0, 2, 5)" << endl;
this->list.remove_at(0);
this->list.remove_at(2);
this->list.remove_at(5);
this->list.print();
this->list.print(kout);
for (unsigned int i = 0; i < 5; ++i) {
this->list.remove_first();
}
this->list.print();
this->list.print(kout);
// ============================================================
@ -63,7 +63,7 @@ void ArrayListDemo::run() {
this->list.insert(1);
this->list.insert(2);
this->list.insert(3);
this->list.print();
this->list.print(kout);
kout << "Starting..." << endl;
for (unsigned int n = 0; n < 10000000; ++n) {
@ -76,12 +76,12 @@ void ArrayListDemo::run() {
}
if (n < 5) {
this->list.print();
this->list.print(kout);
}
}
kout << "Finished." << endl;
this->list.print();
this->list.print(kout);
scheduler.exit();
}

View File

@ -9,14 +9,15 @@ void PreemptiveLoopThread::run() {
// Saving + restoring kout position doesn't help much as preemption still occurs,
// only LoopThreads are synchronized, so other output will be disturbed sometimes
// kout.setpos(55, this->id);
// kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
kout.setpos(55, this->id);
kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
sem->v();
}
}
void PreemptiveThreadDemo::run() {
kout << "Preemptive Thread Demo" << endl;
kout << "Initializing Semaphore" << endl;
Semaphore* sem = new Semaphore(1); // Create this semaphore on the heap as this thread exits itself,
// so stack allocated objects will be lost

View File

@ -5,18 +5,19 @@
// NOTE: Implement this here as we need to include globals for printing
template<typename T>
void ArrayList<T>::print() const {
void ArrayList<T>::print(OutStream& out) const {
if (this->buffer_pos == 0) {
kout << "Print List (0 elements)" << endl;
out << "Print List (0 elements)" << endl;
return;
}
kout << "Print List (" << dec << this->buffer_pos << " elements): ";
out << "Print List (" << dec << this->buffer_pos << " elements): ";
for (unsigned int i = 0; i < this->buffer_pos; ++i) {
kout << dec << this->get(i) << " ";
out << dec << this->get(i) << " ";
}
kout << endl;
out << endl;
}
// List all types that are used with print()
template class ArrayList<int>;
template class ArrayList<Thread*>;

View File

@ -6,6 +6,7 @@
// ArrayList instead, without additional effort.
// It's also cool to use the allocator a bit more and introduce realloc because I coded that thing
#include "lib/OutStream.h"
#include <cstddef>
// I put the whole implementation in the header because the templating makes it cumbersome to split
@ -184,7 +185,7 @@ public:
return this->buffer_pos;
}
void print() const;
void print(OutStream& out) const;
};
#endif