Move process be to RefCounted
This commit is contained in:
parent
2e1357255c
commit
d358c1d672
6 changed files with 16 additions and 11 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue