mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
Scheduler: Use monotonic time for blocking threads
This commit is contained in:
parent
b2585b3577
commit
b4c92c24ee
Notes:
sideshowbarker
2024-07-19 08:14:10 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/b4c92c24ee8 Pull-request: https://github.com/SerenityOS/serenity/pull/1396 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/shannonbooth ✅
2 changed files with 10 additions and 4 deletions
|
@ -67,6 +67,11 @@ static u32 time_slice_for(const Thread& thread)
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeval Scheduler::time_since_boot()
|
||||||
|
{
|
||||||
|
return { TimeManagement::the().seconds_since_boot(), (suseconds_t)TimeManagement::the().ticks_this_second() * 1000 };
|
||||||
|
}
|
||||||
|
|
||||||
Thread* g_finalizer;
|
Thread* g_finalizer;
|
||||||
Thread* g_colonel;
|
Thread* g_colonel;
|
||||||
WaitQueue* g_finalizer_wait_queue;
|
WaitQueue* g_finalizer_wait_queue;
|
||||||
|
@ -138,7 +143,7 @@ Thread::WriteBlocker::WriteBlocker(const FileDescription& description)
|
||||||
if (description.is_socket()) {
|
if (description.is_socket()) {
|
||||||
auto& socket = *description.socket();
|
auto& socket = *description.socket();
|
||||||
if (socket.has_send_timeout()) {
|
if (socket.has_send_timeout()) {
|
||||||
timeval deadline = kgettimeofday();
|
timeval deadline = Scheduler::time_since_boot();
|
||||||
deadline.tv_sec += socket.send_timeout().tv_sec;
|
deadline.tv_sec += socket.send_timeout().tv_sec;
|
||||||
deadline.tv_usec += socket.send_timeout().tv_usec;
|
deadline.tv_usec += socket.send_timeout().tv_usec;
|
||||||
deadline.tv_sec += (socket.send_timeout().tv_usec / 1000000) * 1;
|
deadline.tv_sec += (socket.send_timeout().tv_usec / 1000000) * 1;
|
||||||
|
@ -163,7 +168,7 @@ Thread::ReadBlocker::ReadBlocker(const FileDescription& description)
|
||||||
if (description.is_socket()) {
|
if (description.is_socket()) {
|
||||||
auto& socket = *description.socket();
|
auto& socket = *description.socket();
|
||||||
if (socket.has_receive_timeout()) {
|
if (socket.has_receive_timeout()) {
|
||||||
timeval deadline = kgettimeofday();
|
timeval deadline = Scheduler::time_since_boot();
|
||||||
deadline.tv_sec += socket.receive_timeout().tv_sec;
|
deadline.tv_sec += socket.receive_timeout().tv_sec;
|
||||||
deadline.tv_usec += socket.receive_timeout().tv_usec;
|
deadline.tv_usec += socket.receive_timeout().tv_usec;
|
||||||
deadline.tv_sec += (socket.receive_timeout().tv_usec / 1000000) * 1;
|
deadline.tv_sec += (socket.receive_timeout().tv_usec / 1000000) * 1;
|
||||||
|
@ -325,8 +330,7 @@ bool Scheduler::pick_next()
|
||||||
return context_switch(*g_colonel);
|
return context_switch(*g_colonel);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval now;
|
auto now = time_since_boot();
|
||||||
kgettimeofday(now);
|
|
||||||
|
|
||||||
auto now_sec = now.tv_sec;
|
auto now_sec = now.tv_sec;
|
||||||
auto now_usec = now.tv_usec;
|
auto now_usec = now.tv_usec;
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/IntrusiveList.h>
|
#include <AK/IntrusiveList.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
#include <Kernel/UnixTypes.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ public:
|
||||||
static void initialize();
|
static void initialize();
|
||||||
static void timer_tick(const RegisterState&);
|
static void timer_tick(const RegisterState&);
|
||||||
static bool pick_next();
|
static bool pick_next();
|
||||||
|
static timeval time_since_boot();
|
||||||
static void pick_next_and_switch_now();
|
static void pick_next_and_switch_now();
|
||||||
static void switch_now();
|
static void switch_now();
|
||||||
static bool yield();
|
static bool yield();
|
||||||
|
|
Loading…
Add table
Reference in a new issue