ladybird/Kernel/Tasks/FinalizerTask.cpp
Andrew Kaster 86e3010043 Kernel: Pass trampolines instead of lambdas to create_kernel_process
With -Og, all calls to create_kernel_process were triggering -Wnonnull
when creating these lambdas that get implicitly converted to function
pointers. A different design of create_kernel_process to use
AK::Function instead might avoid this awkward behavior.
2021-05-27 10:21:30 +02:00

32 lines
787 B
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Process.h>
#include <Kernel/Tasks/FinalizerTask.h>
namespace Kernel {
static void finalizer_task(void*)
{
Thread::current()->set_priority(THREAD_PRIORITY_LOW);
for (;;) {
g_finalizer_wait_queue->wait_forever("FinalizerTask");
if (g_finalizer_has_work.exchange(false, AK::MemoryOrder::memory_order_acq_rel) == true)
Thread::finalize_dying_threads();
}
};
void FinalizerTask::spawn()
{
RefPtr<Thread> finalizer_thread;
auto finalizer_process = Process::create_kernel_process(finalizer_thread, "FinalizerTask", finalizer_task, nullptr);
VERIFY(finalizer_process);
g_finalizer = finalizer_thread;
}
}