mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 11:35:07 +00:00
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.
This commit is contained in:
parent
8f3022b5c1
commit
df74a9222f
4 changed files with 40 additions and 15 deletions
|
@ -1,5 +1,6 @@
|
|||
#include <LibCore/CElapsedTimer.h>
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/Time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
void CElapsedTimer::start()
|
||||
|
@ -8,22 +9,12 @@ void CElapsedTimer::start()
|
|||
gettimeofday(&m_start_time, nullptr);
|
||||
}
|
||||
|
||||
inline void timersub(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;
|
||||
}
|
||||
}
|
||||
|
||||
int CElapsedTimer::elapsed() const
|
||||
{
|
||||
ASSERT(is_valid());
|
||||
struct timeval now;
|
||||
gettimeofday(&now, nullptr);
|
||||
struct timeval diff;
|
||||
timersub(&now, &m_start_time, &diff);
|
||||
AK::timeval_sub(&now, &m_start_time, &diff);
|
||||
return diff.tv_sec * 1000 + diff.tv_usec / 1000;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue