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

@ -3,6 +3,7 @@
#include <stdint.h>
#include "lib/linked_list.h"
#include "lib/shared_ptr.h"
// Forward decl due to cyclic dependency.
class Thread;
@ -15,15 +16,14 @@ class Process {
RUNNING,
FINISHED,
};
// Caller takes ownership of returned process.
static Process* RootProcess();
static SharedPtr<Process> RootProcess();
Process(uint64_t elf_ptr);
uint64_t id() { return id_; }
uint64_t cr3() { return cr3_; }
uint64_t id() const { return id_; }
uint64_t cr3() const { return cr3_; }
void CreateThread(uint64_t elf_ptr);
Thread* GetThread(uint64_t tid);
SharedPtr<Thread> GetThread(uint64_t tid);
// Checks the state of all child threads and transitions to
// finished if all have finished.
@ -39,5 +39,5 @@ class Process {
uint64_t next_thread_id_ = 0;
LinkedList<Thread*> threads_;
LinkedList<SharedPtr<Thread>> threads_;
};