mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
Kernel: Don't hold the process list lock while destructing the process
Once we remove the process from the process list, we're free to do whatever we want without any locks.
This commit is contained in:
parent
4520863c0e
commit
98408b8920
1 changed files with 5 additions and 2 deletions
|
@ -302,16 +302,19 @@ bool Process::unref() const
|
|||
// NOTE: We need to obtain the process list lock before doing anything,
|
||||
// because otherwise someone might get in between us lowering the
|
||||
// refcount and acquiring the lock.
|
||||
return processes().with_exclusive([&](auto& list) {
|
||||
auto did_hit_zero = processes().with_exclusive([&](auto& list) {
|
||||
auto new_ref_count = deref_base();
|
||||
if (new_ref_count > 0)
|
||||
return false;
|
||||
|
||||
if (m_list_node.is_in_list())
|
||||
list.remove(*const_cast<Process*>(this));
|
||||
delete this;
|
||||
return true;
|
||||
});
|
||||
|
||||
if (did_hit_zero)
|
||||
delete this;
|
||||
return did_hit_zero;
|
||||
}
|
||||
|
||||
// Make sure the compiler doesn't "optimize away" this function:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue