mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:18:11 +00:00
Kernel: Fix Lock race causing infinite spinning between two threads
We need to account for how many shared lock instances the current thread owns, so that we can properly release such references when yielding execution. We also need to release the process lock when donating.
This commit is contained in:
parent
56701f91f9
commit
c4176b0da1
10 changed files with 359 additions and 96 deletions
|
@ -41,14 +41,11 @@ int Process::sys$donate(pid_t tid)
|
|||
if (tid < 0)
|
||||
return -EINVAL;
|
||||
|
||||
// We don't strictly need to grab the scheduler lock here, but it
|
||||
// will close a race where we can find the thread but it disappears
|
||||
// before we call Scheduler::donate_to.
|
||||
ScopedSpinLock lock(g_scheduler_lock);
|
||||
ScopedCritical critical;
|
||||
auto thread = Thread::from_tid(tid);
|
||||
if (!thread || thread->pid() != pid())
|
||||
return -ESRCH;
|
||||
Scheduler::donate_to(thread, "sys$donate");
|
||||
Thread::current()->donate_without_holding_big_lock(thread, "sys$donate");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue