diff options
author | Robin Burchell <robin+git@viroteck.net> | 2019-05-18 02:00:01 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-18 02:57:38 +0200 |
commit | df74a9222f4e40d7b9ba41c77d443490c97fd333 (patch) | |
tree | 3b81bf13a5a7dc9c3a02af9af692651bee06662c /AK | |
parent | 8f3022b5c17bfd1f796de5e7a40adada6aaea429 (diff) | |
download | serenity-df74a9222f4e40d7b9ba41c77d443490c97fd333.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Time.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/AK/Time.h b/AK/Time.h new file mode 100644 index 0000000000..3839f18f17 --- /dev/null +++ b/AK/Time.h @@ -0,0 +1,25 @@ +#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; + } +} + +} |