mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Ignore allocation failures during thread finalization
We ignore allocation failures above the first 32 guaranteed thread slots, and just flag our future-selves to finalize these threads at a later point.
This commit is contained in:
parent
7e9df6ddba
commit
a0f404551e
Notes:
sideshowbarker
2024-07-17 20:10:27 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/a0f404551e0 Pull-request: https://github.com/SerenityOS/serenity/pull/12145 Reviewed-by: https://github.com/linusg ✅
2 changed files with 11 additions and 4 deletions
|
@ -14,10 +14,12 @@ static void finalizer_task(void*)
|
|||
{
|
||||
Thread::current()->set_priority(THREAD_PRIORITY_LOW);
|
||||
for (;;) {
|
||||
g_finalizer_wait_queue->wait_forever("FinalizerTask");
|
||||
|
||||
// The order of this if-else is important: We want to continue trying to finalize the threads in case
|
||||
// Thread::finalize_dying_threads set g_finalizer_has_work back to true due to OOM conditions
|
||||
if (g_finalizer_has_work.exchange(false, AK::MemoryOrder::memory_order_acq_rel) == true)
|
||||
Thread::finalize_dying_threads();
|
||||
else
|
||||
g_finalizer_wait_queue->wait_forever("FinalizerTask");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -529,8 +529,13 @@ void Thread::finalize_dying_threads()
|
|||
{
|
||||
SpinlockLocker lock(g_scheduler_lock);
|
||||
for_each_in_state(Thread::State::Dying, [&](Thread& thread) {
|
||||
if (thread.is_finalizable())
|
||||
dying_threads.append(&thread);
|
||||
if (!thread.is_finalizable())
|
||||
return;
|
||||
auto result = dying_threads.try_append(&thread);
|
||||
// We ignore allocation failures above the first 32 guaranteed thread slots, and
|
||||
// just flag our future-selves to finalize these threads at a later point
|
||||
if (result.is_error())
|
||||
g_finalizer_has_work.store(true, AK::MemoryOrder::memory_order_release);
|
||||
});
|
||||
}
|
||||
for (auto* thread : dying_threads) {
|
||||
|
|
Loading…
Reference in a new issue