Always create threads in CREATED state.
Simplify the process class to have threads marked as runnable separately.
This commit is contained in:
parent
ef8eb5d993
commit
b0c2a6732b
|
@ -6,6 +6,7 @@
|
||||||
#include "memory/paging_util.h"
|
#include "memory/paging_util.h"
|
||||||
#include "scheduler/process.h"
|
#include "scheduler/process.h"
|
||||||
#include "scheduler/process_manager.h"
|
#include "scheduler/process_manager.h"
|
||||||
|
#include "scheduler/thread.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -58,5 +59,5 @@ void LoadInitProgram() {
|
||||||
prog2.size, *proc,
|
prog2.size, *proc,
|
||||||
proc->vmm().GetNextMemMapAddr(prog2.size));
|
proc->vmm().GetNextMemMapAddr(prog2.size));
|
||||||
|
|
||||||
proc->CreateThread(entry);
|
proc->CreateThread()->Start(entry, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,10 @@ SharedPtr<Process> Process::RootProcess() {
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process::Process() : id_(gNextId++), state_(RUNNING) {}
|
Process::Process() : id_(gNextId++), state_(RUNNING) {
|
||||||
|
caps_.PushBack(new Capability(this, Capability::PROCESS, Z_INIT_PROC_SELF,
|
||||||
|
ZC_PROC_SPAWN_PROC | ZC_PROC_SPAWN_THREAD));
|
||||||
|
}
|
||||||
|
|
||||||
SharedPtr<Thread> Process::CreateThread() {
|
SharedPtr<Thread> Process::CreateThread() {
|
||||||
SharedPtr<Thread> thread{new Thread(*this, next_thread_id_++, 0)};
|
SharedPtr<Thread> thread{new Thread(*this, next_thread_id_++, 0)};
|
||||||
|
@ -29,15 +32,6 @@ SharedPtr<Thread> Process::CreateThread() {
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::CreateThread(uint64_t entry) {
|
|
||||||
Thread* thread = new Thread(*this, next_thread_id_++, entry);
|
|
||||||
threads_.PushBack(thread);
|
|
||||||
caps_.PushBack(new Capability(this, Capability::PROCESS, Z_INIT_PROC_SELF,
|
|
||||||
ZC_PROC_SPAWN_PROC | ZC_PROC_SPAWN_THREAD));
|
|
||||||
thread->SetState(Thread::RUNNABLE);
|
|
||||||
gScheduler->Enqueue(thread);
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedPtr<Thread> Process::GetThread(uint64_t tid) {
|
SharedPtr<Thread> Process::GetThread(uint64_t tid) {
|
||||||
auto iter = threads_.begin();
|
auto iter = threads_.begin();
|
||||||
while (iter != threads_.end()) {
|
while (iter != threads_.end()) {
|
||||||
|
|
|
@ -25,7 +25,6 @@ class Process {
|
||||||
VirtualMemory& vmm() { return vmm_; }
|
VirtualMemory& vmm() { return vmm_; }
|
||||||
|
|
||||||
SharedPtr<Thread> CreateThread();
|
SharedPtr<Thread> CreateThread();
|
||||||
void CreateThread(uint64_t entry);
|
|
||||||
SharedPtr<Thread> GetThread(uint64_t tid);
|
SharedPtr<Thread> GetThread(uint64_t tid);
|
||||||
|
|
||||||
SharedPtr<Capability> GetCapability(uint64_t cid);
|
SharedPtr<Capability> GetCapability(uint64_t cid);
|
||||||
|
|
|
@ -74,7 +74,7 @@ uint64_t ProcessSpawnElf(ZProcessSpawnElfReq* req) {
|
||||||
SharedPtr<Process> proc = MakeShared<Process>();
|
SharedPtr<Process> proc = MakeShared<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(entry);
|
proc->CreateThread()->Start(entry, 0, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue