mirror of
https://github.com/RGBCube/serenity
synced 2025-05-24 21:15:08 +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
|
@ -14,6 +14,7 @@
|
|||
#include <LibC/errno.h>
|
||||
#include <LibC/string.h>
|
||||
#include <LibC/stdlib.h>
|
||||
#include <AK/Time.h>
|
||||
|
||||
//#define CEVENTLOOP_DEBUG
|
||||
//#define DEFERRED_INVOKE_DEBUG
|
||||
|
@ -179,18 +180,22 @@ void CEventLoop::wait_for_event()
|
|||
queued_events_is_empty = m_queued_events.is_empty();
|
||||
}
|
||||
|
||||
timeval now;
|
||||
struct timeval timeout = { 0, 0 };
|
||||
if (!s_timers->is_empty() && queued_events_is_empty)
|
||||
if (!s_timers->is_empty() && queued_events_is_empty) {
|
||||
gettimeofday(&now, nullptr);
|
||||
get_next_timer_expiration(timeout);
|
||||
AK::timeval_sub(&timeout, &now, &timeout);
|
||||
}
|
||||
|
||||
int rc = select(max_fd + 1, &rfds, &wfds, nullptr, (queued_events_is_empty && s_timers->is_empty()) ? nullptr : &timeout);
|
||||
if (rc < 0) {
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
timeval now;
|
||||
if (!s_timers->is_empty())
|
||||
if (!s_timers->is_empty()) {
|
||||
gettimeofday(&now, nullptr);
|
||||
}
|
||||
|
||||
for (auto& it : *s_timers) {
|
||||
auto& timer = *it.value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue