1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00

Kernel: Port Thread to ListedRefCounted

This commit is contained in:
Andreas Kling 2021-08-16 21:52:42 +02:00
parent c410f08c2b
commit 62719b85e0
2 changed files with 9 additions and 25 deletions

View file

@ -32,25 +32,11 @@ namespace Kernel {
static Singleton<SpinLockProtectedValue<Thread::GlobalList>> s_list;
SpinLockProtectedValue<Thread::GlobalList>& Thread::all_threads()
SpinLockProtectedValue<Thread::GlobalList>& Thread::all_instances()
{
return *s_list;
}
bool Thread::unref() const
{
bool did_hit_zero = all_threads().with([&](auto&) {
if (deref_base())
return false;
m_global_thread_list_node.remove();
return true;
});
if (did_hit_zero)
delete this;
return did_hit_zero;
}
KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> process)
{
auto kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, {}, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow);
@ -91,7 +77,7 @@ Thread::Thread(NonnullRefPtr<Process> process, NonnullOwnPtr<Memory::Region> ker
m_kernel_stack_region->set_name(KString::try_create(string));
}
all_threads().with([&](auto& list) {
Thread::all_instances().with([&](auto& list) {
list.append(*this);
});
@ -1258,7 +1244,7 @@ KResult Thread::make_thread_specific_region(Badge<Process>)
RefPtr<Thread> Thread::from_tid(ThreadID tid)
{
return all_threads().with([&](auto& list) -> RefPtr<Thread> {
return Thread::all_instances().with([&](auto& list) -> RefPtr<Thread> {
for (Thread& thread : list) {
if (thread.tid() == tid)
return thread;