Skip to content

Commit

Permalink
Static variables refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed Nov 15, 2016
1 parent 061a9ef commit ac1f306
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/kernlib/display.cpp
Expand Up @@ -127,9 +127,9 @@ void EFIDisplay::write(const char *str) {
mutex.release();
}

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

Display *Display::initInstance() {
if (EFI::getSystemTable()) return new EFIDisplay();
Expand Down
1 change: 1 addition & 0 deletions src/kernlib/include/kernlib/display.hpp
Expand Up @@ -20,6 +20,7 @@

class Display {
private:
static Mutex instanceMutex;
static Display *initInstance();
static Display *instance;
protected:
Expand Down
6 changes: 3 additions & 3 deletions src/kernlib/printf.cpp
Expand Up @@ -16,9 +16,9 @@

#include "kernlib.hpp"

static char *longlong_to_string(char *buf, size_t len, uint64_t n, uint8_t base,
bool fl_signed, bool fl_showsign,
bool fl_caps) {
static inline char *longlong_to_string(
char *buf, size_t len, uint64_t n, uint8_t base,
bool fl_signed, bool fl_showsign, bool fl_caps) {
int pos = len;
char table_start = fl_caps ? 'A' : 'a';
bool negative = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/platform/acpi.cpp
Expand Up @@ -20,16 +20,14 @@
#include "cpu.hpp"
#include "pagetable.hpp"

Mutex ACPI::controllerMutex;
ACPI* ACPI::controller = 0;
uint8_t ACPI::activeCpuCount = 0;
uint64_t ACPI::busfreq = 0;

static const void *const ACPI_FIND_START = reinterpret_cast<char*>(0x000e0000);
static const void *const ACPI_FIND_TOP = reinterpret_cast<char*>(0x000fffff);
static const uint64_t ACPI_SIG_RTP_DSR = 0x2052545020445352;
static const uint32_t ACPI_SIG_CIPA = 0x43495041;

static Mutex controllerMutex;
ACPI* ACPI::getController() {
if (controller) return controller;
uint64_t t = EnterCritical();
Expand Down
8 changes: 5 additions & 3 deletions src/platform/include/acpi.hpp
Expand Up @@ -111,13 +111,15 @@ struct ioapic_redir {

class ACPI {
private:
static Mutex controllerMutex;
static ACPI *controller;

char *localApicAddr, *ioApicAddr;
uint8_t ioApicMaxCount;
uint32_t acpiCpuIds[256];
uint8_t acpiCpuCount;
static uint8_t activeCpuCount;
static uint64_t busfreq;
static ACPI *controller;
uint8_t activeCpuCount;
uint64_t busfreq;
bool ParseRsdp(const void* rsdp);
void ParseRsdt(const AcpiHeader* rsdt);
void ParseXsdt(const AcpiHeader* xsdt);
Expand Down
1 change: 1 addition & 0 deletions src/platform/include/smp.hpp
Expand Up @@ -19,6 +19,7 @@

class SMP {
private:
static Mutex startupMutex;
static void NORETURN startup();
public:
static void init();
Expand Down
10 changes: 5 additions & 5 deletions src/platform/smp.cpp
Expand Up @@ -18,13 +18,13 @@
#include "acpi.hpp"
#include "processmanager.hpp"

static Mutex cpuinit;
Mutex SMP::startupMutex;

void SMP::startup() {
Interrupts::loadVector();
ACPI::getController()->activateCPU();
cpuinit.lock();
cpuinit.release();
startupMutex.lock();
startupMutex.release();
process_loop();
}

Expand Down Expand Up @@ -80,7 +80,7 @@ void SMP::init() {
if (nullcpus > 0)
nullcpus--;

cpuinit.lock();
startupMutex.lock();

for (uint32_t i = 0; i < cpuCount; i++) {
if (info->cpuids[i] != localId) {
Expand All @@ -95,7 +95,7 @@ void SMP::init() {
}
}

cpuinit.release();
startupMutex.release();

delete[] info->cpuids;
delete[] info->stacks;
Expand Down
1 change: 1 addition & 0 deletions src/process/include/modules.hpp
Expand Up @@ -24,6 +24,7 @@ struct MODULEINFO {
};
class ModuleManager {
private:
static Mutex managerMutex;
static ModuleManager* manager;
void parseInternal();
void parseInitRD();
Expand Down
4 changes: 3 additions & 1 deletion src/process/include/processmanager.hpp
Expand Up @@ -30,13 +30,15 @@ struct QueuedThread {

class ProcessManager {
private:
static Mutex managerMutex;
static ProcessManager* manager;

ProcessManager();
QueuedThread *nextThread, *lastThread;
QueuedThread **cpuThreads;
Thread *nullThreads;
List<Process*> processes;
Mutex processSwitchMutex;
static ProcessManager* manager;
bool SwitchProcess(intcb_regs *regs);
bool HandleFault(uint32_t intr, uint32_t code, intcb_regs *regs);
static bool TimerHandler(uint32_t intr, uint32_t code, intcb_regs *regs);
Expand Down
8 changes: 5 additions & 3 deletions src/process/modules.cpp
Expand Up @@ -19,6 +19,8 @@
#include "readelf.hpp"
#include "multiboot_info.hpp"

Mutex ModuleManager::managerMutex;

bool ModuleManager::parseModuleInfo(MODULEINFO *info, Process *process) {
struct {
uintptr_t entry, name, version, desc, reqs, dev;
Expand Down Expand Up @@ -110,13 +112,13 @@ void ModuleManager::init() {
mm->parseInternal();
mm->parseInitRD();
}
static Mutex moduleManagerMutex;

ModuleManager* ModuleManager::getManager() {
if (manager) return manager;
moduleManagerMutex.lock();
managerMutex.lock();
if (!manager)
manager = new ModuleManager();
moduleManagerMutex.release();
managerMutex.release();
return manager;
}
ModuleManager::ModuleManager() {}
4 changes: 3 additions & 1 deletion src/process/processmanager.cpp
Expand Up @@ -32,8 +32,9 @@ void process_loop() {
_loop();
}

Mutex ProcessManager::managerMutex;
ProcessManager* ProcessManager::manager = 0;
static Mutex managerMutex;

ProcessManager* ProcessManager::getManager() {
if (manager) return manager;
uint64_t t = EnterCritical();
Expand All @@ -44,6 +45,7 @@ ProcessManager* ProcessManager::getManager() {
LeaveCritical(t);
return manager;
}

ProcessManager::ProcessManager() {
nextThread = lastThread = 0;
uint64_t cpus = ACPI::getController()->getCPUCount();
Expand Down

0 comments on commit ac1f306

Please sign in to comment.