summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/sched.cpp
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-12-14 16:36:22 -0700
committerAndreas Kling <kling@serenityos.org>2020-12-16 23:38:17 +0100
commitc4176b0da1000d1cba663fc5cb0f34efb1df394a (patch)
tree3c0ab1f1e11830486498cd17557bea3650df9128 /Kernel/Syscalls/sched.cpp
parent56701f91f90415329fe60a3bb8fb269fb0a71129 (diff)
downloadserenity-c4176b0da1000d1cba663fc5cb0f34efb1df394a.zip
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.
Diffstat (limited to 'Kernel/Syscalls/sched.cpp')
-rw-r--r--Kernel/Syscalls/sched.cpp7
1 files changed, 2 insertions, 5 deletions
diff --git a/Kernel/Syscalls/sched.cpp b/Kernel/Syscalls/sched.cpp
index 8882a0c627..f497a26ca0 100644
--- a/Kernel/Syscalls/sched.cpp
+++ b/Kernel/Syscalls/sched.cpp
@@ -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;
}