Kernel: Port process thread lists to SpinLockProtectedValue

I had to move the thread list out of the protected base area of Process
so that it could live with its lock (which needs to be mutable).
Ideally it would live in the protected area, so maybe we can figure out
a way to do that later.
This commit is contained in:
Andreas Kling 2021-08-07 13:28:18 +02:00
parent d6667e4cb8
commit b197fc40a7
Notes: sideshowbarker 2024-07-18 07:19:14 +09:00
3 changed files with 38 additions and 27 deletions

View file

@ -856,8 +856,9 @@ bool Process::remove_thread(Thread& thread)
ProtectedDataMutationScope scope { *this };
auto thread_cnt_before = m_thread_count.fetch_sub(1, AK::MemoryOrder::memory_order_acq_rel);
VERIFY(thread_cnt_before != 0);
ScopedSpinLock thread_list_lock(m_thread_list_lock);
m_thread_list.remove(thread);
thread_list().with([&](auto& thread_list) {
thread_list.remove(thread);
});
return thread_cnt_before == 1;
}
@ -865,8 +866,9 @@ bool Process::add_thread(Thread& thread)
{
ProtectedDataMutationScope scope { *this };
bool is_first = m_thread_count.fetch_add(1, AK::MemoryOrder::memory_order_relaxed) == 0;
ScopedSpinLock thread_list_lock(m_thread_list_lock);
m_thread_list.append(thread);
thread_list().with([&](auto& thread_list) {
thread_list.append(thread);
});
return is_first;
}