Move process be to RefCounted
This commit is contained in:
parent
2e1357255c
commit
d358c1d672
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "boot/boot_info.h"
|
#include "boot/boot_info.h"
|
||||||
#include "debug/debug.h"
|
#include "debug/debug.h"
|
||||||
|
#include "lib/ref_ptr.h"
|
||||||
#include "loader/elf_loader.h"
|
#include "loader/elf_loader.h"
|
||||||
#include "memory/paging_util.h"
|
#include "memory/paging_util.h"
|
||||||
#include "scheduler/process.h"
|
#include "scheduler/process.h"
|
||||||
|
@ -49,7 +50,7 @@ void LoadInitProgram() {
|
||||||
const limine_file& init_prog = GetInitProgram("/sys/test");
|
const limine_file& init_prog = GetInitProgram("/sys/test");
|
||||||
const limine_file& prog2 = GetInitProgram("/sys/test2");
|
const limine_file& prog2 = GetInitProgram("/sys/test2");
|
||||||
|
|
||||||
SharedPtr<Process> proc = MakeShared<Process>();
|
RefPtr<Process> proc = MakeRefCounted<Process>();
|
||||||
gProcMan->InsertProcess(proc);
|
gProcMan->InsertProcess(proc);
|
||||||
|
|
||||||
uint64_t entry = LoadElfProgram(
|
uint64_t entry = LoadElfProgram(
|
||||||
|
|
|
@ -13,13 +13,14 @@ static uint64_t gNextId = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr<Process> Process::RootProcess() {
|
RefPtr<Process> Process::RootProcess() {
|
||||||
SharedPtr<Process> proc(new Process(0));
|
RefPtr<Process> proc = MakeRefCounted<Process>(0);
|
||||||
proc->threads_.PushBack(Thread::RootThread(*proc));
|
proc->threads_.PushBack(Thread::RootThread(*proc));
|
||||||
proc->next_thread_id_ = 1;
|
proc->next_thread_id_ = 1;
|
||||||
|
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
RefPtr<Process> Process::Create() { return MakeRefCounted<Process>(); }
|
||||||
|
|
||||||
Process::Process() : id_(gNextId++), state_(RUNNING) {
|
Process::Process() : id_(gNextId++), state_(RUNNING) {
|
||||||
caps_.PushBack(new Capability(this, Capability::PROCESS, Z_INIT_PROC_SELF,
|
caps_.PushBack(new Capability(this, Capability::PROCESS, Z_INIT_PROC_SELF,
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "capability/capability.h"
|
#include "capability/capability.h"
|
||||||
#include "lib/linked_list.h"
|
#include "lib/linked_list.h"
|
||||||
|
#include "lib/ref_counted.h"
|
||||||
#include "lib/ref_ptr.h"
|
#include "lib/ref_ptr.h"
|
||||||
#include "lib/shared_ptr.h"
|
#include "lib/shared_ptr.h"
|
||||||
#include "memory/virtual_memory.h"
|
#include "memory/virtual_memory.h"
|
||||||
|
@ -11,7 +12,7 @@
|
||||||
// Forward decl due to cyclic dependency.
|
// Forward decl due to cyclic dependency.
|
||||||
class Thread;
|
class Thread;
|
||||||
|
|
||||||
class Process {
|
class Process : public RefCounted<Process> {
|
||||||
public:
|
public:
|
||||||
enum State {
|
enum State {
|
||||||
UNSPECIFIED,
|
UNSPECIFIED,
|
||||||
|
@ -19,8 +20,8 @@ class Process {
|
||||||
RUNNING,
|
RUNNING,
|
||||||
FINISHED,
|
FINISHED,
|
||||||
};
|
};
|
||||||
static SharedPtr<Process> RootProcess();
|
static RefPtr<Process> RootProcess();
|
||||||
Process();
|
static RefPtr<Process> Create();
|
||||||
|
|
||||||
uint64_t id() const { return id_; }
|
uint64_t id() const { return id_; }
|
||||||
VirtualMemory& vmm() { return vmm_; }
|
VirtualMemory& vmm() { return vmm_; }
|
||||||
|
@ -37,6 +38,8 @@ class Process {
|
||||||
State GetState() { return state_; }
|
State GetState() { return state_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class MakeRefCountedFriend<Process>;
|
||||||
|
Process();
|
||||||
Process(uint64_t id) : id_(id), vmm_(VirtualMemory::ForRoot()) {}
|
Process(uint64_t id) : id_(id), vmm_(VirtualMemory::ForRoot()) {}
|
||||||
uint64_t id_;
|
uint64_t id_;
|
||||||
VirtualMemory vmm_;
|
VirtualMemory vmm_;
|
||||||
|
|
|
@ -7,7 +7,7 @@ void ProcessManager::Init() {
|
||||||
gProcMan->InsertProcess(Process::RootProcess());
|
gProcMan->InsertProcess(Process::RootProcess());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessManager::InsertProcess(const SharedPtr<Process>& proc) {
|
void ProcessManager::InsertProcess(const RefPtr<Process>& proc) {
|
||||||
proc_list_.PushBack(proc);
|
proc_list_.PushBack(proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "lib/linked_list.h"
|
#include "lib/linked_list.h"
|
||||||
#include "lib/shared_ptr.h"
|
#include "lib/ref_ptr.h"
|
||||||
#include "scheduler/process.h"
|
#include "scheduler/process.h"
|
||||||
|
|
||||||
class ProcessManager {
|
class ProcessManager {
|
||||||
|
@ -10,14 +10,14 @@ class ProcessManager {
|
||||||
// and stores it in the global variable.
|
// and stores it in the global variable.
|
||||||
static void Init();
|
static void Init();
|
||||||
|
|
||||||
void InsertProcess(const SharedPtr<Process>& proc);
|
void InsertProcess(const RefPtr<Process>& proc);
|
||||||
Process& FromId(uint64_t id);
|
Process& FromId(uint64_t id);
|
||||||
|
|
||||||
void DumpProcessStates();
|
void DumpProcessStates();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TODO: This should be a hashmap.
|
// TODO: This should be a hashmap.
|
||||||
LinkedList<SharedPtr<Process>> proc_list_;
|
LinkedList<RefPtr<Process>> proc_list_;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ProcessManager* gProcMan;
|
extern ProcessManager* gProcMan;
|
||||||
|
|
|
@ -71,7 +71,7 @@ uint64_t ProcessSpawnElf(ZProcessSpawnElfReq* req) {
|
||||||
return ZE_DENIED;
|
return ZE_DENIED;
|
||||||
}
|
}
|
||||||
dbgln("Proc spawn: %u:%u", req->elf_base, req->elf_size);
|
dbgln("Proc spawn: %u:%u", req->elf_base, req->elf_size);
|
||||||
SharedPtr<Process> proc = MakeShared<Process>();
|
RefPtr<Process> proc = MakeRefCounted<Process>();
|
||||||
gProcMan->InsertProcess(proc);
|
gProcMan->InsertProcess(proc);
|
||||||
uint64_t entry = LoadElfProgram(*proc, req->elf_base, req->elf_size);
|
uint64_t entry = LoadElfProgram(*proc, req->elf_base, req->elf_size);
|
||||||
proc->CreateThread()->Start(entry, 0, 0);
|
proc->CreateThread()->Start(entry, 0, 0);
|
||||||
|
|
Loading…
Reference in New Issue