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