diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-25 13:03:49 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-25 13:03:49 +0100 |
commit | 500df578fe5b24d14062d030c5628cbb4b69d3a6 (patch) | |
tree | e484af9a08e7463e95e947f8e8af3b94fb3d6645 /Kernel/Process.cpp | |
parent | 108b663618e893c804c150205a21f2e8d95088c2 (diff) | |
download | serenity-500df578fe5b24d14062d030c5628cbb4b69d3a6.zip |
LibGUI+Kernel: Add a GLock class (userspace mutex.)
It's basically a userspace port of the kernel's Lock class.
Added gettid() and donate() syscalls to support the timeslice donation
feature we already enjoyed in the kernel.
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r-- | Kernel/Process.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 363487ebd5..c7b009aeb7 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2461,3 +2461,27 @@ int Process::sys$create_thread(int(*entry)(void*), void* argument) thread->set_state(Thread::State::Runnable); return 0; } + +int Process::sys$gettid() +{ + return current->tid(); +} + +int Process::sys$donate(int tid) +{ + if (tid < 0) + return -EINVAL; + InterruptDisabler disabler; + Thread* beneficiary = nullptr; + for_each_thread([&] (Thread& thread) { + if (thread.tid() == tid) { + beneficiary = &thread; + return IterationDecision::Abort; + } + return IterationDecision::Continue; + }); + if (!beneficiary) + return -ENOTHREAD; + Scheduler::donate_to(beneficiary, "sys$donate"); + return 0; +} |