Create a RefCounted type and use it for Thread.

This should prevent me from actually creating 2 shared ptrs of
a single kernel object with their separate ref counts.
This commit is contained in:
Drew Galbraith 2023-06-06 19:05:03 -07:00
parent d9b17d96d7
commit 2e1357255c
8 changed files with 146 additions and 22 deletions

View file

@ -2,12 +2,13 @@
#include <stdint.h>
#include "lib/shared_ptr.h"
#include "lib/ref_counted.h"
#include "lib/ref_ptr.h"
// Forward decl due to cyclic dependency.
class Process;
class Thread {
class Thread : public RefCounted<Thread> {
public:
enum State {
UNSPECIFIED,
@ -16,9 +17,8 @@ class Thread {
RUNNABLE,
FINISHED,
};
static SharedPtr<Thread> RootThread(Process& root_proc);
Thread(Process& proc, uint64_t tid);
static RefPtr<Thread> RootThread(Process& root_proc);
static RefPtr<Thread> Create(Process& proc, uint64_t tid);
uint64_t tid() const { return id_; };
uint64_t pid() const;
@ -40,6 +40,8 @@ class Thread {
void Exit();
private:
friend class MakeRefCountedFriend<Thread>;
Thread(Process& proc, uint64_t tid);
// Special constructor for the root thread only.
Thread(Process& proc) : process_(proc), id_(0) {}
Process& process_;