1

use static logger

This commit is contained in:
2022-07-22 23:32:46 +02:00
parent ec09b0e6d2
commit bd95c02a08
24 changed files with 139 additions and 151 deletions

View File

@ -10,114 +10,114 @@ void SmartPointerDemo::run() {
kout << "Output is written to log to be able to trace memory allocations/deallocations" << endl;
{
log << INFO << "Allocating new unique_ptr<int>..." << endl;
log.info() << "Allocating new unique_ptr<int>..." << endl;
bse::unique_ptr<int> ptr = bse::make_unique<int>(1);
log << INFO << "Leaving scope..." << endl;
log.info() << "Leaving scope..." << endl;
}
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
{
log << INFO << "Allocating new unique_ptr<int>..." << endl;
log.info() << "Allocating new unique_ptr<int>..." << endl;
bse::unique_ptr<int> ptr1 = bse::make_unique<int>(1);
bse::unique_ptr<int> ptr2;
log << INFO << "*ptr1 == " << *ptr1 << ", (bool)ptr2 == " << (bool)ptr2 << endl;
log << INFO << "Moving ptr1 => ptr2 (no allocations should happen)..." << endl;
log.info() << "*ptr1 == " << *ptr1 << ", (bool)ptr2 == " << (bool)ptr2 << endl;
log.info() << "Moving ptr1 => ptr2 (no allocations should happen)..." << endl;
ptr2 = std::move(ptr1);
log << INFO << "(bool)ptr1 == " << (bool)ptr1 << ", *ptr2 == " << *ptr2 << endl;
log.info() << "(bool)ptr1 == " << (bool)ptr1 << ", *ptr2 == " << *ptr2 << endl;
log << INFO << "Leaving scope..." << endl;
log.info() << "Leaving scope..." << endl;
}
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
{
log << INFO << "Allocating (2) new unique_ptr<int>..." << endl;
log.info() << "Allocating (2) new unique_ptr<int>..." << endl;
bse::unique_ptr<int> ptr1 = bse::make_unique<int>(1);
bse::unique_ptr<int> ptr2 = bse::make_unique<int>(1);
log << INFO << "Moving ptr1 => ptr2 (ptr1 should be freed)..." << endl;
log.info() << "Moving ptr1 => ptr2 (ptr1 should be freed)..." << endl;
ptr2 = std::move(ptr1);
log << INFO << "Leaving scope..." << endl;
log.info() << "Leaving scope..." << endl;
}
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
// =====================================================================
{
log << INFO << "Allocating new unique_ptr<int[]>..." << endl;
log.info() << "Allocating new unique_ptr<int[]>..." << endl;
bse::unique_ptr<int[]> ptr = bse::make_unique<int[]>(10);
ptr[0] = 1;
log << INFO << "ptr[0] == " << ptr[0] << endl;
log.info() << "ptr[0] == " << ptr[0] << endl;
}
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
{
log << INFO << "Allocating new unique_ptr<int[10]>..." << endl;
log.info() << "Allocating new unique_ptr<int[10]>..." << endl;
bse::unique_ptr<int[]> ptr1 = bse::make_unique<int[]>(10);
bse::unique_ptr<int[]> ptr2;
log << INFO << "Moving ptr1 => ptr2 (no allocations should happen)..." << endl;
log.info() << "Moving ptr1 => ptr2 (no allocations should happen)..." << endl;
ptr2 = std::move(ptr1);
log << INFO << "Leaving scope..." << endl;
log.info() << "Leaving scope..." << endl;
}
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
{
log << INFO << "Allocating (2) new unique_ptr<int[10]>..." << endl;
log.info() << "Allocating (2) new unique_ptr<int[10]>..." << endl;
bse::unique_ptr<int> ptr1 = bse::make_unique<int>(10);
bse::unique_ptr<int> ptr2 = bse::make_unique<int>(10);
log << INFO << "Moving ptr1 => ptr2 (ptr1 should be freed)..." << endl;
log.info() << "Moving ptr1 => ptr2 (ptr1 should be freed)..." << endl;
ptr2 = std::move(ptr1);
log << INFO << "Leaving scope..." << endl;
log.info() << "Leaving scope..." << endl;
}
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
// NOTE: This wasn't working because of a missing operator[] delete in the allocator
log << INFO << "Allocating unique_ptr<int>*..." << endl;
log.info() << "Allocating unique_ptr<int>*..." << endl;
bse::unique_ptr<int>* ptrptr = new bse::unique_ptr<int>[10];
delete[] ptrptr;
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
// =====================================================================
{
log << INFO << "Stackallocating Array<bse::unique_ptr<int>, 10>..." << endl;
log.info() << "Stackallocating Array<bse::unique_ptr<int>, 10>..." << endl;
bse::Array<bse::unique_ptr<int>, 10> arr;
log << INFO << "Populating slot 0..." << endl;
log.info() << "Populating slot 0..." << endl;
arr[0] = bse::make_unique<int>(1);
log << INFO << "Moving slot 0 to slot 1..." << endl;
log.info() << "Moving slot 0 to slot 1..." << endl;
arr[1] = std::move(arr[0]);
log << INFO << "Leaving scope" << endl;
log.info() << "Leaving scope" << endl;
}
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
{
log << INFO << "Heapallocating Array<bse::unique_ptr<int>, 10>..." << endl;
log.info() << "Heapallocating Array<bse::unique_ptr<int>, 10>..." << endl;
bse::Array<bse::unique_ptr<int>, 10>* arr = new bse::Array<bse::unique_ptr<int>, 10>;
log << INFO << "Populating slot 0..." << endl;
log.info() << "Populating slot 0..." << endl;
(*arr)[0] = bse::make_unique<int>(1);
log << INFO << "Moving slot 0 to slot 1..." << endl;
log.info() << "Moving slot 0 to slot 1..." << endl;
(*arr)[1] = std::move((*arr)[0]);
log << INFO << "Deleting" << endl;
log.info() << "Deleting" << endl;
delete arr;
log << INFO << "Leaving scope" << endl;
log.info() << "Leaving scope" << endl;
}
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
{
log << INFO << "ArrayList<bse::unique_ptr<int>>..." << endl;
log.info() << "ArrayList<bse::unique_ptr<int>>..." << endl;
bse::Vector<bse::unique_ptr<int>> vec;
log << INFO << "2x insertion" << endl;
log.info() << "2x insertion" << endl;
vec.push_back(bse::make_unique<int>(1));
vec.push_back(bse::make_unique<int>(2));
log << INFO << "Leaving scope" << endl;
log.info() << "Leaving scope" << endl;
}
log << INFO << "Should be deleted by now..." << endl;
log.info() << "Should be deleted by now..." << endl;
kout.unlock();
scheduler.exit();

View File

@ -1,14 +1,12 @@
#include "user/event/KeyEventListener.h"
#include "kernel/Globals.h"
Logger KeyEventListener::log("KEvLis");
void KeyEventListener::trigger(char c) {
this->lastChar = c;
}
char KeyEventListener::waitForKeyEvent() const {
log << DEBUG << "Thread with id: " << tid << " waiting for key event" << endl;
Logger::instance() << DEBUG << "KEvLis:: Thread with id: " << tid << " waiting for key event" << endl;
scheduler.block();
return this->lastChar; // This is only executed after thread is woken up by manager
}

View File

@ -7,8 +7,6 @@ class KeyEventListener {
private:
KeyEventListener(const KeyEventListener& copy) = delete;
static Logger log;
char lastChar = '\0';
public:

View File

@ -2,12 +2,12 @@
#include "kernel/Globals.h"
void KeyEventManager::subscribe(KeyEventListener& sub) {
log << DEBUG << "Subscribe, Thread ID: " << dec << sub.tid << endl;
log.debug() << "Subscribe, Thread ID: " << dec << sub.tid << endl;
this->listeners.push_back(&sub);
}
void KeyEventManager::unsubscribe(KeyEventListener& unsub) {
log << DEBUG << "Unsubscribe, Thread ID: " << dec << unsub.tid << endl;
log.debug() << "Unsubscribe, Thread ID: " << dec << unsub.tid << endl;
for (bse::Vector<KeyEventListener*>::Iterator it = listeners.begin(); it != listeners.end(); ++it) {
if ((*it)->tid == unsub.tid) {
this->listeners.erase(it);
@ -17,9 +17,9 @@ void KeyEventManager::unsubscribe(KeyEventListener& unsub) {
}
void KeyEventManager::broadcast(char c) {
log << TRACE << "Beginning Broadcast" << endl;
log.trace() << "Beginning Broadcast" << endl;
for (KeyEventListener* listener : this->listeners) {
log << TRACE << "Broadcasting " << c << " to Thread ID: " << dec << listener->tid << endl;
log.trace() << "Broadcasting " << c << " to Thread ID: " << dec << listener->tid << endl;
listener->trigger(c);
scheduler.deblock(listener->tid);
}

View File

@ -12,7 +12,7 @@ class KeyEventManager {
private:
KeyEventManager(const KeyEventManager& copy) = delete;
Logger log;
NamedLogger log;
bse::Vector<KeyEventListener*> listeners;