Move Processes and Threads to be stored in SharedPtr

Reference counting lets us pass these around a bit more easily.

SharedPtr was lightly tested using uint64_t in the main zion funcion.

Also add a sleep functionality instead of panicking. Functionally the
same right now since we don't preempt.
This commit is contained in:
Drew Galbraith 2023-05-29 15:50:38 -07:00
parent 9f3ffbf5b4
commit 80d2bf1aaa
6 changed files with 96 additions and 23 deletions

View file

@ -12,11 +12,11 @@ static uint64_t gNextId = 1;
}
Process* Process::RootProcess() {
SharedPtr<Process> Process::RootProcess() {
uint64_t pml4_addr = 0;
asm volatile("mov %%cr3, %0;" : "=r"(pml4_addr));
Process* proc = new Process(0, pml4_addr);
proc->threads_.PushBack(Thread::RootThread(proc));
SharedPtr<Process> proc(new Process(0, pml4_addr));
proc->threads_.PushBack(Thread::RootThread(proc.ptr()));
proc->next_thread_id_ = 1;
return proc;
@ -34,7 +34,7 @@ void Process::CreateThread(uint64_t elf_ptr) {
sched::EnqueueThread(thread);
}
Thread* Process::GetThread(uint64_t tid) {
SharedPtr<Thread> Process::GetThread(uint64_t tid) {
auto iter = threads_.begin();
while (iter != threads_.end()) {
if (iter->tid() == tid) {