Move Process & Thread to the object folder.
This commit is contained in:
parent
4e278a4664
commit
b5ad454ad1
12 changed files with 16 additions and 16 deletions
79
zion/object/process.cpp
Normal file
79
zion/object/process.cpp
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#include "object/process.h"
|
||||
|
||||
#include "debug/debug.h"
|
||||
#include "include/zcall.h"
|
||||
#include "memory/paging_util.h"
|
||||
#include "memory/physical_memory.h"
|
||||
#include "object/thread.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
namespace {
|
||||
|
||||
static uint64_t gNextId = 1;
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
auto proc = MakeRefCounted<Process>();
|
||||
proc->caps_.PushBack(
|
||||
new Capability(proc, Capability::PROCESS, Z_INIT_PROC_SELF,
|
||||
ZC_PROC_SPAWN_PROC | ZC_PROC_SPAWN_THREAD));
|
||||
return proc;
|
||||
}
|
||||
|
||||
Process::Process() : id_(gNextId++), state_(RUNNING) {}
|
||||
|
||||
RefPtr<Thread> Process::CreateThread() {
|
||||
RefPtr<Thread> thread = MakeRefCounted<Thread>(*this, next_thread_id_++);
|
||||
threads_.PushBack(thread);
|
||||
return thread;
|
||||
}
|
||||
|
||||
RefPtr<Thread> Process::GetThread(uint64_t tid) {
|
||||
auto iter = threads_.begin();
|
||||
while (iter != threads_.end()) {
|
||||
if (iter->tid() == tid) {
|
||||
return *iter;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
panic("Bad thread access.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Process::CheckState() {
|
||||
auto iter = threads_.begin();
|
||||
while (iter != threads_.end()) {
|
||||
if (iter->GetState() != Thread::FINISHED) {
|
||||
return;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
state_ = FINISHED;
|
||||
}
|
||||
|
||||
SharedPtr<Capability> Process::GetCapability(uint64_t cid) {
|
||||
auto iter = caps_.begin();
|
||||
while (iter != caps_.end()) {
|
||||
if (iter->id() == cid) {
|
||||
return *iter;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
dbgln("Bad cap access");
|
||||
dbgln("Num caps: %u", caps_.size());
|
||||
return {};
|
||||
}
|
||||
|
||||
uint64_t Process::AddCapability(const RefPtr<Thread>& thread) {
|
||||
uint64_t cap_id = next_cap_id_++;
|
||||
caps_.PushBack(new Capability(thread, Capability::THREAD, cap_id, ZC_WRITE));
|
||||
return cap_id;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue