ladybird/AK/Time.h
Robin Burchell df74a9222f Kernel: Fix timeout support in select
The scheduler expects m_select_timeout to act as a deadline. That is, it
should contain the time that a task should wake at -- but we were
directly copying the time from userspace, which meant that it always
returned virtually immediately.

At the same time, fix CEventLoop to not rely on the broken select behavior
by subtracting the current time from the time of the nearest timer.
2019-05-18 02:57:38 +02:00

25 lines
624 B
C++

#pragma once
namespace AK {
inline void timeval_sub(const struct timeval* a, const struct timeval* b, struct timeval* result)
{
result->tv_sec = a->tv_sec - b->tv_sec;
result->tv_usec = a->tv_usec - b->tv_usec;
if (result->tv_usec < 0) {
--result->tv_sec;
result->tv_usec += 1000000;
}
}
inline void timeval_add(const struct timeval* a, const struct timeval* b, struct timeval* result)
{
result->tv_sec = a->tv_sec + b->tv_sec;
result->tv_usec = a->tv_usec + b->tv_usec;
if (result->tv_usec > 1000000) {
++result->tv_sec;
result->tv_usec -= 1000000;
}
}
}