Unverified Commit 6365427f authored by PhoeniX's avatar PhoeniX

Refactor const methods

parent 1a76fb55
......@@ -10,6 +10,7 @@ class List {
Item *items = nullptr;
size_t count = 0;
size_t capacity = 0;
public:
~List() { Heap::free(items); }
......@@ -26,7 +27,8 @@ class List {
void add(const Item &item) { insert() = item; }
size_t getCount() { return count; }
size_t getCount() const { return count; }
Item& operator[] (const size_t index) { return items[index]; }
const Item& operator[] (const size_t index) const { return items[index]; }
};
......@@ -16,7 +16,7 @@ class ModuleManager {
void parseInternal();
void parseInitRD();
void loadStream(Stream *stream);
bool parseModuleInfo(ModuleInfo *info, Process *process);
bool parseModuleInfo(ModuleInfo *info, const Process *process);
bool bindRequirement(const char *req, Process *process);
bool bindRequirements(const char *reqs, Process *process);
static void init();
......
......@@ -40,14 +40,14 @@ class Process {
void exit(int code);
void addThread(Thread *thread, bool suspended);
uint64_t getId() { return id; }
uint64_t getId() const { return id; }
Pagetable::Entry *pagetable;
uintptr_t addSection(SectionType type, size_t size);
void addSymbol(const char *name, uintptr_t ptr);
void setEntryAddress(uintptr_t ptr);
uintptr_t getSymbolByName(const char* name) PURE;
uintptr_t getSymbolByName(const char* name) const PURE;
uintptr_t linkLibrary(const char* funcname);
void allowIOPorts(uint16_t min, uint16_t max);
......
......@@ -4,9 +4,7 @@
#pragma once
#include "kernlib.hpp"
class Thread {
public:
Thread();
struct Thread {
struct {
uint64_t rip, rflags;
uint64_t rsi, rdi, rbp, rsp;
......@@ -16,4 +14,5 @@ class Thread {
} regs;
uint64_t suspend_ticks;
uint64_t stack_top;
Thread() : regs(), suspend_ticks(0), stack_top(0) {}
};
......@@ -9,11 +9,10 @@
volatile ModuleManager* ModuleManager::manager = nullptr;
Mutex ModuleManager::managerMutex;
bool ModuleManager::parseModuleInfo(ModuleInfo *info, Process *process) {
bool ModuleManager::parseModuleInfo(ModuleInfo *info, const Process *process) {
struct {
uintptr_t entry, name, version, desc, reqs, dev;
uintptr_t name, version, desc, reqs, dev;
} symbols = {
process->getSymbolByName("module"),
process->getSymbolByName("module_name"),
process->getSymbolByName("module_version"),
process->getSymbolByName("module_description"),
......@@ -22,12 +21,10 @@ bool ModuleManager::parseModuleInfo(ModuleInfo *info, Process *process) {
};
ModuleInfo mod = { nullptr, nullptr, nullptr, nullptr, nullptr };
if ((symbols.entry == 0) || (symbols.name == 0) || (symbols.version == 0)
if ((symbols.name == 0) || (symbols.version == 0)
|| (symbols.desc == 0) || (symbols.reqs == 0) || (symbols.dev == 0))
return false;
process->setEntryAddress(symbols.entry);
mod.name = process->readString(symbols.name);
mod.version = process->readString(symbols.version);
mod.description = process->readString(symbols.desc);
......
......@@ -137,7 +137,7 @@ void Process::addSymbol(const char *name, uintptr_t ptr) {
void Process::setEntryAddress(uintptr_t ptr) {
entry = ptr;
}
uintptr_t Process::getSymbolByName(const char* name) {
uintptr_t Process::getSymbolByName(const char* name) const {
for (size_t i = 0; i < symbols.getCount(); i++) {
if (klib::strcmp(symbols[i].name, name) == 0)
return symbols[i].ptr;
......
// PhoeniX OS Thread subsystem
// Copyright © 2017 Yury Popov a.k.a. PhoeniX
#include "thread.hpp"
Thread::Thread() {
regs = {
0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
suspend_ticks = 0;
stack_top = 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment