mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:47:35 +00:00
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.
This commit is contained in:
parent
108b663618
commit
500df578fe
10 changed files with 176 additions and 12 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -97,6 +97,8 @@ public:
|
|||
void die();
|
||||
void finalize();
|
||||
|
||||
int sys$gettid();
|
||||
int sys$donate(int tid);
|
||||
pid_t sys$setsid();
|
||||
pid_t sys$getsid(pid_t);
|
||||
int sys$setpgid(pid_t pid, pid_t pgid);
|
||||
|
|
|
@ -57,6 +57,10 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
|
|||
case Syscall::SC_yield:
|
||||
Scheduler::yield();
|
||||
break;
|
||||
case Syscall::SC_donate:
|
||||
return current->process().sys$donate((int)arg1);
|
||||
case Syscall::SC_gettid:
|
||||
return current->process().sys$gettid();
|
||||
case Syscall::SC_putch:
|
||||
Console::the().put_char(arg1 & 0xff);
|
||||
break;
|
||||
|
|
|
@ -93,6 +93,8 @@
|
|||
__ENUMERATE_SYSCALL(getsockopt) \
|
||||
__ENUMERATE_SYSCALL(setsockopt) \
|
||||
__ENUMERATE_SYSCALL(create_thread) \
|
||||
__ENUMERATE_SYSCALL(gettid) \
|
||||
__ENUMERATE_SYSCALL(donate) \
|
||||
|
||||
|
||||
namespace Syscall {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue