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

@ -26,13 +26,13 @@ Process::Process() : id_(gNextId++), state_(RUNNING) {
ZC_PROC_SPAWN_PROC | ZC_PROC_SPAWN_THREAD));
}
SharedPtr<Thread> Process::CreateThread() {
SharedPtr<Thread> thread{new Thread(*this, next_thread_id_++)};
RefPtr<Thread> Process::CreateThread() {
RefPtr<Thread> thread = MakeRefCounted<Thread>(*this, next_thread_id_++);
threads_.PushBack(thread);
return thread;
}
SharedPtr<Thread> Process::GetThread(uint64_t tid) {
RefPtr<Thread> Process::GetThread(uint64_t tid) {
auto iter = threads_.begin();
while (iter != threads_.end()) {
if (iter->tid() == tid) {
@ -67,9 +67,9 @@ SharedPtr<Capability> Process::GetCapability(uint64_t cid) {
return {};
}
uint64_t Process::AddCapability(SharedPtr<Thread>& thread) {
uint64_t Process::AddCapability(RefPtr<Thread>& thread) {
uint64_t cap_id = next_cap_id_++;
caps_.PushBack(
new Capability(thread.ptr(), Capability::THREAD, cap_id, ZC_WRITE));
new Capability(thread.get(), Capability::THREAD, cap_id, ZC_WRITE));
return cap_id;
}