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

Kernel: Make Thread refcounted

Similar to Process, we need to make Thread refcounted. This will solve
problems that will appear once we schedule threads on more than one
processor. This allows us to hold onto threads without necessarily
holding the scheduler lock for the entire duration.
This commit is contained in:
Tom 2020-09-27 08:53:35 -06:00 committed by Andreas Kling
parent 079486ed7e
commit 838d9fa251
14 changed files with 136 additions and 90 deletions

View file

@ -50,7 +50,7 @@ class SchedulerPerProcessorData {
public:
SchedulerPerProcessorData() = default;
Thread* m_pending_beneficiary { nullptr };
WeakPtr<Thread> m_pending_beneficiary;
const char* m_pending_donate_reason { nullptr };
bool m_in_scheduler { true };
};
@ -599,7 +599,7 @@ bool Scheduler::donate_to_and_switch(Thread* beneficiary, const char* reason)
return Scheduler::context_switch(beneficiary);
}
bool Scheduler::donate_to(Thread* beneficiary, const char* reason)
bool Scheduler::donate_to(RefPtr<Thread>& beneficiary, const char* reason)
{
ASSERT(beneficiary);
@ -625,7 +625,7 @@ bool Scheduler::donate_to(Thread* beneficiary, const char* reason)
ASSERT(!proc.in_irq());
if (proc.in_critical() > 1) {
scheduler_data.m_pending_beneficiary = beneficiary; // Save the beneficiary
scheduler_data.m_pending_beneficiary = beneficiary->make_weak_ptr(); // Save the beneficiary
scheduler_data.m_pending_donate_reason = reason;
proc.invoke_scheduler_async();
return false;
@ -740,7 +740,7 @@ void Scheduler::initialize()
{
ASSERT(&Processor::current() != nullptr); // sanity check
Thread* idle_thread = nullptr;
RefPtr<Thread> idle_thread;
g_scheduler_data = new SchedulerData;
g_finalizer_wait_queue = new WaitQueue;