mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[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:
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user