mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:57:44 +00:00
Kernel: Move some time related code from Scheduler into TimeManagement
Use the TimerQueue to expire blocking operations, which is one less thing the Scheduler needs to check on every iteration. Also, add a BlockTimeout class that will automatically handle relative or absolute timeouts as well as overriding timeouts (e.g. socket timeouts) more consistently. Also, rework the TimerQueue class to be able to fire events from any processor, which requires Timer to be RefCounted. Also allow creating id-less timers for use by blocking operations.
This commit is contained in:
parent
e0e26c6c67
commit
6cb640eeba
19 changed files with 461 additions and 263 deletions
|
@ -29,19 +29,6 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
static void compute_relative_timeout_from_absolute(const timeval& absolute_time, timeval& relative_time)
|
||||
{
|
||||
// Convert absolute time to relative time of day.
|
||||
timeval_sub(absolute_time, kgettimeofday(), relative_time);
|
||||
}
|
||||
|
||||
static void compute_relative_timeout_from_absolute(const timespec& absolute_time, timeval& relative_time)
|
||||
{
|
||||
timeval tv_absolute_time;
|
||||
timespec_to_timeval(absolute_time, tv_absolute_time);
|
||||
compute_relative_timeout_from_absolute(tv_absolute_time, relative_time);
|
||||
}
|
||||
|
||||
WaitQueue& Process::futex_queue(Userspace<const i32*> userspace_address)
|
||||
{
|
||||
auto& queue = m_futex_queues.ensure(userspace_address.ptr());
|
||||
|
@ -66,20 +53,17 @@ int Process::sys$futex(Userspace<const Syscall::SC_futex_params*> user_params)
|
|||
if (user_value != params.val)
|
||||
return -EAGAIN;
|
||||
|
||||
timespec ts_abstimeout { 0, 0 };
|
||||
if (params.timeout && !copy_from_user(&ts_abstimeout, params.timeout))
|
||||
return -EFAULT;
|
||||
|
||||
timeval* optional_timeout = nullptr;
|
||||
timeval relative_timeout { 0, 0 };
|
||||
Thread::BlockTimeout timeout;
|
||||
if (params.timeout) {
|
||||
compute_relative_timeout_from_absolute(ts_abstimeout, relative_timeout);
|
||||
optional_timeout = &relative_timeout;
|
||||
timespec ts_abstimeout { 0, 0 };
|
||||
if (!copy_from_user(&ts_abstimeout, params.timeout))
|
||||
return -EFAULT;
|
||||
timeout = Thread::BlockTimeout(true, &ts_abstimeout);
|
||||
}
|
||||
|
||||
// FIXME: This is supposed to be interruptible by a signal, but right now WaitQueue cannot be interrupted.
|
||||
WaitQueue& wait_queue = futex_queue((FlatPtr)params.userspace_address);
|
||||
Thread::BlockResult result = Thread::current()->wait_on(wait_queue, "Futex", optional_timeout);
|
||||
Thread::BlockResult result = Thread::current()->wait_on(wait_queue, "Futex", timeout);
|
||||
if (result == Thread::BlockResult::InterruptedByTimeout) {
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue