Skip to content

Commit

Permalink
Display init refactoring, move cleanup to instance constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed Nov 14, 2016
1 parent cd7879e commit f507551
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/boot/boot.cpp
Expand Up @@ -23,7 +23,6 @@
#include "processmanager.hpp"

void NORETURN main() {
Display::getInstance()->clean();
Pagetable::init();
SMP::init();
ModuleManager::init();
Expand Down
15 changes: 9 additions & 6 deletions src/kernlib/display.cpp
Expand Up @@ -22,6 +22,7 @@ const size_t ConsoleDisplay::size = ConsoleDisplay::top - ConsoleDisplay::base;

ConsoleDisplay::ConsoleDisplay() {
display = base;
clean();
}

void ConsoleDisplay::putc(const char c) {
Expand Down Expand Up @@ -60,16 +61,18 @@ void ConsoleDisplay::clean() {
}

static Mutex instanceMutex;
static ConsoleDisplay defaultDisplay;
Display *Display::instance;
static ConsoleDisplay sharedConsole;
Display *Display::instance = Display::initInstance();

Display *Display::initInstance() {
return &sharedConsole;
}

Display *Display::getInstance() {
if (instance) return instance;
instanceMutex.lock();
if (!instance) {
instance = &defaultDisplay;
// TODO: create dynamic instance
}
if (!instance)
instance = initInstance();
instanceMutex.release();
return instance;
}
Expand Down
4 changes: 3 additions & 1 deletion src/kernlib/include/kernlib/display.hpp
Expand Up @@ -20,7 +20,10 @@

class Display {
private:
static Display *initInstance();
static Display *instance;
protected:
Mutex mutex;
public:
static Display *getInstance();
virtual void clean() = 0;
Expand All @@ -35,7 +38,6 @@ class ConsoleDisplay: public Display {
static const size_t size;
char *display;
void putc(const char c);
Mutex mutex;
public:
ConsoleDisplay();
void write(const char *str);
Expand Down

0 comments on commit f507551

Please sign in to comment.