1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 03:08:11 +00:00

Kernel: Use a WaitQueue to implement finalizer wakeup

This gets rid of the special "Lurking" thread state and replaces it
with a generic WaitQueue :^)
This commit is contained in:
Andreas Kling 2019-12-01 19:17:17 +01:00
parent 5a45376180
commit 8bb98aa31b
5 changed files with 9 additions and 9 deletions

View file

@ -46,6 +46,7 @@ static u32 time_slice_for(ThreadPriority priority)
Thread* current;
Thread* g_last_fpu_thread;
Thread* g_finalizer;
WaitQueue* g_finalizer_wait_queue;
static Process* s_colonel_process;
u64 g_uptime;
static u64 s_beep_timeout;
@ -257,6 +258,7 @@ void Thread::consider_unblock(time_t now_sec, long now_usec)
case Thread::Dead:
case Thread::Stopped:
case Thread::Queued:
case Thread::Dying:
/* don't know, don't care */
return;
case Thread::Blocked:
@ -270,11 +272,6 @@ void Thread::consider_unblock(time_t now_sec, long now_usec)
case Thread::Skip0SchedulerPasses:
set_state(Thread::Runnable);
return;
case Thread::Dying:
ASSERT(g_finalizer);
if (g_finalizer->is_blocked())
g_finalizer->unblock();
return;
}
}
@ -534,6 +531,7 @@ Process* Scheduler::colonel()
void Scheduler::initialize()
{
g_scheduler_data = new SchedulerData;
g_finalizer_wait_queue = new WaitQueue;
s_redirection.selector = gdt_alloc_entry();
initialize_redirection();
s_colonel_process = Process::create_kernel_process("colonel", nullptr);

View file

@ -7,12 +7,14 @@
class Process;
class Thread;
class WaitQueue;
struct RegisterDump;
struct SchedulerData;
extern Thread* current;
extern Thread* g_last_fpu_thread;
extern Thread* g_finalizer;
extern WaitQueue* g_finalizer_wait_queue;
extern u64 g_uptime;
extern SchedulerData* g_scheduler_data;

View file

@ -661,6 +661,9 @@ void Thread::set_state(State new_state)
if (m_process.pid() != 0) {
Scheduler::update_state_for_thread(*this);
}
if (new_state == Dying)
g_finalizer_wait_queue->wake_all();
}
String Thread::backtrace(ProcessInspectionHandle&) const

View file

@ -209,7 +209,6 @@ public:
class SemiPermanentBlocker final : public Blocker {
public:
enum class Reason {
Lurking,
Signal,
};
@ -218,8 +217,6 @@ public:
virtual const char* state_string() const override
{
switch (m_reason) {
case Reason::Lurking:
return "Lurking";
case Reason::Signal:
return "Signal";
}

View file

@ -319,8 +319,8 @@ extern "C" [[noreturn]] void init(u32 physical_address_for_kernel_page_tables)
g_finalizer = current;
current->set_priority(ThreadPriority::Low);
for (;;) {
current->wait_on(*g_finalizer_wait_queue);
Thread::finalize_dying_threads();
(void)current->block<Thread::SemiPermanentBlocker>(Thread::SemiPermanentBlocker::Reason::Lurking);
}
});