mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 02:50:26 +00:00
0810c1b972
This abstraction layer is mainly for ATA ports (AHCI ports, IDE ports). The goal is to create a convenient and flexible framework so it's possible to expand to support other types of controller (e.g. Intel PIIX and ICH IDE controllers) and to abstract operations that are possible on each component. Currently only the ATA IDE code is affected by this, making it much cleaner and readable - the ATA bus mastering code is moved to the ATAPort code so more implementations in the near future can take advantage of such functionality easily. In addition to that, the hierarchy of the ATA IDE code resembles more of the SATA AHCI code now, which means the IDEChannel class is solely responsible for getting interrupts, passing them for further processing in the ATAPort code to take care of the rest of the handling logic.
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <Kernel/Process.h>
|
|
#include <Kernel/Sections.h>
|
|
#include <Kernel/WaitQueue.h>
|
|
#include <Kernel/WorkQueue.h>
|
|
|
|
namespace Kernel {
|
|
|
|
WorkQueue* g_io_work;
|
|
WorkQueue* g_ata_work;
|
|
|
|
UNMAP_AFTER_INIT void WorkQueue::initialize()
|
|
{
|
|
g_io_work = new WorkQueue("IO WorkQueue Task"sv);
|
|
g_ata_work = new WorkQueue("ATA WorkQueue Task"sv);
|
|
}
|
|
|
|
UNMAP_AFTER_INIT WorkQueue::WorkQueue(StringView name)
|
|
{
|
|
RefPtr<Thread> thread;
|
|
auto name_kstring = KString::try_create(name);
|
|
if (name_kstring.is_error())
|
|
TODO();
|
|
(void)Process::create_kernel_process(thread, name_kstring.release_value(), [this] {
|
|
for (;;) {
|
|
WorkItem* item;
|
|
bool have_more;
|
|
m_items.with([&](auto& items) {
|
|
item = items.take_first();
|
|
have_more = !items.is_empty();
|
|
});
|
|
if (item) {
|
|
item->function();
|
|
delete item;
|
|
|
|
if (have_more)
|
|
continue;
|
|
}
|
|
[[maybe_unused]] auto result = m_wait_queue.wait_on({});
|
|
}
|
|
});
|
|
// If we can't create the thread we're in trouble...
|
|
m_thread = thread.release_nonnull();
|
|
}
|
|
|
|
void WorkQueue::do_queue(WorkItem& item)
|
|
{
|
|
m_items.with([&](auto& items) {
|
|
items.append(item);
|
|
});
|
|
m_wait_queue.wake_one();
|
|
}
|
|
|
|
}
|