[kernel] Protect process::m_threads with a lock

Another spot I meant to go back and clean up with a lock - found it when
a process with threads running on two CPUs exited, and the scheduler
tried to delete the process on both CPUs.
This commit is contained in:
Justin C. Miller
2023-02-14 20:25:19 -08:00
parent bce01591f3
commit 2c2398b549
2 changed files with 16 additions and 1 deletions

View File

@@ -52,7 +52,11 @@ process::create_kernel_process(page_table *pml4)
void
process::exit(int32_t code)
{
// TODO: make this thread-safe
util::scoped_lock lock {m_threads_lock};
if (m_state == state::exited)
return;
m_state = state::exited;
m_return_code = code;
@@ -67,6 +71,9 @@ process::exit(int32_t code)
void
process::update()
{
util::scoped_lock lock {m_threads_lock};
kassert(false, "process::update used!");
kassert(m_threads.count() > 0, "process::update with zero threads!");
size_t i = 0;
@@ -86,6 +93,11 @@ process::update()
thread *
process::create_thread(uintptr_t rsp3, uint8_t priority)
{
util::scoped_lock lock {m_threads_lock};
if (m_state == state::exited)
return nullptr;
if (priority == default_priority)
priority = scheduler::default_priority;
@@ -103,6 +115,8 @@ process::create_thread(uintptr_t rsp3, uint8_t priority)
bool
process::thread_exited(thread *th)
{
util::scoped_lock lock {m_threads_lock};
kassert(&th->m_parent == this, "Process got thread_exited for non-child!");
m_threads.remove_swap(th);
remove_handle(th->self_handle());

View File

@@ -111,6 +111,7 @@ private:
vm_space m_space;
util::vector<thread*> m_threads;
util::spinlock m_threads_lock;
util::node_set<j6_handle_t, j6_handle_invalid, heap_allocated> m_handles;
util::spinlock m_handles_lock;