mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
Kernel: Move sync and finalization tasks into their own files
Instead of clogging up the initialization sequence, put these tasks in their own files.
This commit is contained in:
parent
befe4c6709
commit
a066dd1fac
Notes:
sideshowbarker
2024-07-19 07:48:27 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a066dd1fac2
6 changed files with 168 additions and 21 deletions
|
@ -98,6 +98,8 @@ OBJS = \
|
|||
Scheduler.o \
|
||||
SharedBuffer.o \
|
||||
Syscall.o \
|
||||
Tasks/FinalizerTask.o \
|
||||
Tasks/SyncTask.o \
|
||||
TimerQueue.o \
|
||||
TTY/MasterPTY.o \
|
||||
TTY/PTYMultiplexer.o \
|
||||
|
|
49
Kernel/Tasks/FinalizerTask.cpp
Normal file
49
Kernel/Tasks/FinalizerTask.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Tasks/FinalizerTask.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
void FinalizerTask::spawn()
|
||||
{
|
||||
Process::create_kernel_process(g_finalizer, "FinalizerTask", [] {
|
||||
Thread::current->set_priority(THREAD_PRIORITY_LOW);
|
||||
for (;;) {
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (!g_finalizer_has_work)
|
||||
Thread::current->wait_on(*g_finalizer_wait_queue);
|
||||
ASSERT(g_finalizer_has_work);
|
||||
g_finalizer_has_work = false;
|
||||
}
|
||||
Thread::finalize_dying_threads();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
34
Kernel/Tasks/FinalizerTask.h
Normal file
34
Kernel/Tasks/FinalizerTask.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Kernel {
|
||||
class FinalizerTask {
|
||||
public:
|
||||
static void spawn();
|
||||
};
|
||||
}
|
45
Kernel/Tasks/SyncTask.cpp
Normal file
45
Kernel/Tasks/SyncTask.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Tasks/SyncTask.h>
|
||||
#include <Kernel/Time/TimeManagement.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
void SyncTask::spawn()
|
||||
{
|
||||
Thread* syncd_thread = nullptr;
|
||||
Process::create_kernel_process(syncd_thread, "SyncTask", [] {
|
||||
for (;;) {
|
||||
VFS::the().sync();
|
||||
Thread::current->sleep(1 * TimeManagement::the().ticks_per_second());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
34
Kernel/Tasks/SyncTask.h
Normal file
34
Kernel/Tasks/SyncTask.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Kernel {
|
||||
class SyncTask {
|
||||
public:
|
||||
static void spawn();
|
||||
};
|
||||
}
|
|
@ -66,6 +66,8 @@
|
|||
#include <Kernel/RTC.h>
|
||||
#include <Kernel/Random.h>
|
||||
#include <Kernel/Scheduler.h>
|
||||
#include <Kernel/Tasks/FinalizerTask.h>
|
||||
#include <Kernel/Tasks/SyncTask.h>
|
||||
#include <Kernel/TTY/PTYMultiplexer.h>
|
||||
#include <Kernel/TTY/VirtualConsole.h>
|
||||
#include <Kernel/Time/TimeManagement.h>
|
||||
|
@ -164,27 +166,8 @@ extern "C" [[noreturn]] void init()
|
|||
|
||||
void init_stage2()
|
||||
{
|
||||
Thread* syncd_thread = nullptr;
|
||||
Process::create_kernel_process(syncd_thread, "syncd", [] {
|
||||
for (;;) {
|
||||
VFS::the().sync();
|
||||
Thread::current->sleep(1 * TimeManagement::the().ticks_per_second());
|
||||
}
|
||||
});
|
||||
|
||||
Process::create_kernel_process(g_finalizer, "Finalizer", [] {
|
||||
Thread::current->set_priority(THREAD_PRIORITY_LOW);
|
||||
for (;;) {
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (!g_finalizer_has_work)
|
||||
Thread::current->wait_on(*g_finalizer_wait_queue);
|
||||
ASSERT(g_finalizer_has_work);
|
||||
g_finalizer_has_work = false;
|
||||
}
|
||||
Thread::finalize_dying_threads();
|
||||
}
|
||||
});
|
||||
SyncTask::spawn();
|
||||
FinalizerTask::spawn();
|
||||
|
||||
// Sample test to see if the ACPI parser is working...
|
||||
klog() << "ACPI: HPET table @ " << ACPI::Parser::the().find_table("HPET");
|
||||
|
|
Loading…
Reference in a new issue