Kernel: Refactor includes to reduce include dependencies

Now modifying Scheduler.h or Thread.h doesnt trigger practically a full
kernel rebuild. This required moving Mutex and RWLock of of line but
that should be fine :^)
This commit is contained in:
2026-08-19 21:32:36 +03:00
parent 8cd9e6dfa8
commit bf0bd19289
62 changed files with 321 additions and 214 deletions
+2
View File
@@ -51,6 +51,8 @@ set(KERNEL_SOURCES
kernel/Interruptable.cpp
kernel/InterruptController.cpp
kernel/kernel.cpp
kernel/Lock/Mutex.cpp
kernel/Lock/RWLock.cpp
kernel/Lock/SpinLock.cpp
kernel/Memory/ByteRingBuffer.cpp
kernel/Memory/DMARegion.cpp
+1
View File
@@ -4,6 +4,7 @@
#include <kernel/ACPI/AML/Namespace.h>
#include <kernel/ACPI/EmbeddedController.h>
#include <kernel/ACPI/Headers.h>
#include <kernel/Interruptable.h>
#include <kernel/Memory/Types.h>
#include <kernel/ThreadBlocker.h>
@@ -1,11 +1,12 @@
#pragma once
#include <BAN/Atomic.h>
#include <BAN/Optional.h>
#include <BAN/UniqPtr.h>
#include <kernel/ACPI/AML/Scope.h>
#include <kernel/Lock/Mutex.h>
#include <kernel/Thread.h>
#include <kernel/ThreadBlocker.h>
namespace Kernel::ACPI
{
+1
View File
@@ -2,6 +2,7 @@
#include <BAN/Vector.h>
#include <kernel/InterruptController.h>
#include <kernel/InterruptNumbers.h>
#include <kernel/Lock/SpinLock.h>
#include <kernel/Memory/Types.h>
@@ -1,5 +1,6 @@
#pragma once
#include <BAN/Optional.h>
#include <BAN/Vector.h>
namespace Kernel::HDAudio
+1
View File
@@ -3,6 +3,7 @@
#include <BAN/HashMap.h>
#include <kernel/FS/Inode.h>
#include <kernel/Lock/Mutex.h>
#include <kernel/ThreadBlocker.h>
#include <sys/epoll.h>
+2 -1
View File
@@ -1,7 +1,6 @@
#pragma once
#include <BAN/Vector.h>
#include <kernel/Device/Device.h>
#include <kernel/FS/TmpFS/FileSystem.h>
#include <kernel/Lock/Mutex.h>
#include <kernel/ThreadBlocker.h>
@@ -9,6 +8,8 @@
namespace Kernel
{
class Device;
class DevFileSystem final : public TmpFileSystem
{
public:
+1
View File
@@ -2,6 +2,7 @@
#include <kernel/FS/Inode.h>
#include <kernel/Lock/Mutex.h>
#include <kernel/ThreadBlocker.h>
namespace Kernel
{
+2 -1
View File
@@ -2,8 +2,9 @@
#include <BAN/HashMap.h>
#include <kernel/Device/Device.h>
#include <kernel/FS/FileSystem.h>
#include <kernel/FS/Ext2/Inode.h>
#include <kernel/FS/FileSystem.h>
#include <kernel/Memory/VirtualRange.h>
namespace Kernel
{
@@ -5,6 +5,7 @@
#include <kernel/FS/FAT/Definitions.h>
#include <kernel/FS/FAT/Inode.h>
#include <kernel/FS/FileSystem.h>
#include <kernel/Lock/Mutex.h>
namespace Kernel
{
+2 -1
View File
@@ -1,11 +1,12 @@
#pragma once
#include <kernel/Device/Device.h>
#include <kernel/FS/Inode.h>
namespace Kernel
{
class BlockDevice;
class FileSystem : public BAN::RefCounted<FileSystem>
{
public:
+2 -1
View File
@@ -2,11 +2,12 @@
#include <kernel/FS/TmpFS/FileSystem.h>
#include <kernel/FS/TmpFS/Inode.h>
#include <kernel/Process.h>
namespace Kernel
{
class Process;
class ProcFileSystem final : public TmpFileSystem
{
public:
+2 -1
View File
@@ -2,11 +2,12 @@
#include <kernel/FS/TmpFS/FileSystem.h>
#include <kernel/FS/TmpFS/Inode.h>
#include <kernel/Process.h>
namespace Kernel
{
class Process;
class ProcPidInode final : public TmpDirectoryInode
{
// FIXME: dynamically update ruid/rgid.
-15
View File
@@ -10,21 +10,6 @@
namespace Kernel
{
// IDT entries
// 0x00->0x1F (32): ISR
// 0x20->0x7F (96): PIC/IOAPIC
// 0x80->0xEF (112): MSI
// 0xF0->0xFE (15): internal
constexpr uint8_t IRQ_VECTOR_BASE = 0x20;
constexpr uint8_t IRQ_MSI_BASE = 0x80;
constexpr uint8_t IRQ_MSI_END = 0xF0;
#if ARCH(i686)
constexpr uint8_t IRQ_SYSCALL = 0xF0; // hard coded in kernel/API/Syscall.h
#endif
constexpr uint8_t IRQ_IPI = 0xF1;
constexpr uint8_t IRQ_TIMER = 0xF2;
#if ARCH(x86_64)
struct GateDescriptor
{
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include <kernel/Arch.h>
namespace Kernel
{
// IDT entries
// 0x00->0x1F (32): ISR
// 0x20->0x7F (96): PIC/IOAPIC
// 0x80->0xEF (112): MSI
// 0xF0->0xFE (15): internal
constexpr uint8_t IRQ_VECTOR_BASE = 0x20;
constexpr uint8_t IRQ_MSI_BASE = 0x80;
constexpr uint8_t IRQ_MSI_END = 0xF0;
#if ARCH(i686)
constexpr uint8_t IRQ_SYSCALL = 0xF0; // hard coded in kernel/API/Syscall.h
#endif
constexpr uint8_t IRQ_IPI = 0xF1;
constexpr uint8_t IRQ_TIMER = 0xF2;
}
+8 -118
View File
@@ -2,7 +2,6 @@
#include <BAN/Atomic.h>
#include <BAN/NoCopyMove.h>
#include <kernel/Thread.h>
#include <sys/types.h>
@@ -27,63 +26,14 @@ namespace Kernel
public:
Mutex() = default;
void lock() override
{
const auto tid = Thread::current_tid();
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
ASSERT(!tid || !Thread::current().has_spinlock());
pid_t expected = -1;
while (!m_locker.compare_exchange(expected, tid))
{
ASSERT(Processor::get_interrupt_state() == InterruptState::Enabled);
Processor::yield();
expected = -1;
}
ASSERT(m_lock_depth == 0);
if (tid)
Thread::current().add_mutex();
}
m_lock_depth++;
}
bool try_lock()
{
const auto tid = Thread::current_tid();
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
pid_t expected = -1;
if (!m_locker.compare_exchange(expected, tid))
return false;
ASSERT(m_lock_depth == 0);
if (tid)
Thread::current().add_mutex();
}
m_lock_depth++;
return true;
}
void unlock() override
{
const auto tid = Thread::current_tid();
ASSERT(m_locker == tid);
ASSERT(m_lock_depth > 0);
if (--m_lock_depth == 0)
{
m_locker = -1;
if (tid)
Thread::current().remove_mutex();
}
}
bool try_lock();
void lock() override;
void unlock() override;
pid_t locker() const { return m_locker; }
bool is_locked() const { return m_locker != -1; }
uint32_t lock_depth() const override { return m_lock_depth; }
bool is_locked_by_current_thread() const override { return m_locker == Thread::current_tid(); }
bool is_locked_by_current_thread() const override;
private:
BAN::Atomic<pid_t> m_locker { -1 };
@@ -98,74 +48,14 @@ namespace Kernel
public:
PriorityMutex() = default;
void lock() override
{
const auto tid = Thread::current_tid();
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
ASSERT(!tid || !Thread::current().has_spinlock());
bool has_priority = tid ? !Thread::current().is_userspace() : true;
if (has_priority)
m_queue_length++;
pid_t expected = -1;
while (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(expected, tid))
{
ASSERT(Processor::get_interrupt_state() == InterruptState::Enabled);
Processor::yield();
expected = -1;
}
ASSERT(m_lock_depth == 0);
if (tid)
Thread::current().add_mutex();
}
m_lock_depth++;
}
bool try_lock()
{
const auto tid = Thread::current_tid();
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
bool has_priority = tid ? !Thread::current().is_userspace() : true;
pid_t expected = -1;
if (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(expected, tid))
return false;
if (has_priority)
m_queue_length++;
ASSERT(m_lock_depth == 0);
if (tid)
Thread::current().add_mutex();
}
m_lock_depth++;
return true;
}
void unlock() override
{
const auto tid = Thread::current_tid();
ASSERT(m_locker == tid);
ASSERT(m_lock_depth > 0);
if (--m_lock_depth == 0)
{
bool has_priority = tid ? !Thread::current().is_userspace() : true;
if (has_priority)
m_queue_length--;
m_locker = -1;
if (tid)
Thread::current().remove_mutex();
}
}
bool try_lock();
void lock() override;
void unlock() override;
pid_t locker() const { return m_locker; }
bool is_locked() const { return m_locker != -1; }
uint32_t lock_depth() const override { return m_lock_depth; }
bool is_locked_by_current_thread() const override { return m_locker == Thread::current_tid(); }
bool is_locked_by_current_thread() const override;
private:
BAN::Atomic<pid_t> m_locker { -1 };
+5 -49
View File
@@ -1,7 +1,7 @@
#pragma once
#include <kernel/Lock/BlockableSpinLock.h>
#include <kernel/Lock/SpinLock.h>
#include <kernel/ThreadBlocker.h>
namespace Kernel
{
@@ -13,54 +13,10 @@ namespace Kernel
public:
RWLock() = default;
void rd_lock()
{
SpinLockGuard _(m_lock);
while (m_writers_waiting > 0 || m_writer != -1)
{
BlockableSpinLock block(m_lock);
m_thread_blocker.block_indefinite(&block);
}
m_readers_active++;
}
void rd_unlock()
{
SpinLockGuard _(m_lock);
if (--m_readers_active == 0)
m_thread_blocker.unblock();
}
void wr_lock()
{
if (m_writer == Thread::current_tid())
{
m_writer_depth++;
return;
}
SpinLockGuard _(m_lock);
m_writers_waiting++;
while (m_readers_active > 0 || m_writer != -1)
{
BlockableSpinLock block(m_lock);
m_thread_blocker.block_indefinite(&block);
}
m_writers_waiting--;
m_writer = Thread::current_tid();
m_writer_depth = 1;
}
void wr_unlock()
{
if (--m_writer_depth != 0)
return;
SpinLockGuard _(m_lock);
m_writer = -1;
m_thread_blocker.unblock();
}
void rd_lock();
void rd_unlock();
void wr_lock();
void wr_unlock();
private:
SpinLock m_lock;
@@ -1,5 +1,6 @@
#pragma once
#include <BAN/Vector.h>
#include <kernel/Memory/MemoryRegion.h>
namespace Kernel
@@ -1,7 +1,9 @@
#pragma once
#include <BAN/HashMap.h>
#include <BAN/RefPtr.h>
#include <BAN/UniqPtr.h>
#include <BAN/Vector.h>
#include <kernel/Lock/Mutex.h>
#include <kernel/Lock/SpinLock.h>
#include <kernel/Memory/MemoryRegion.h>
@@ -4,8 +4,6 @@
#include <BAN/HashMap.h>
#include <BAN/UniqPtr.h>
#include <kernel/Networking/NetworkInterface.h>
#include <kernel/Thread.h>
#include <kernel/ThreadBlocker.h>
namespace Kernel
{
@@ -11,7 +11,6 @@
#include <kernel/Networking/NetworkInterface.h>
#include <kernel/Networking/NetworkLayer.h>
#include <kernel/Networking/NetworkSocket.h>
#include <kernel/Thread.h>
namespace Kernel
{
@@ -1,6 +1,7 @@
#pragma once
#include <kernel/Networking/NetworkInterface.h>
#include <kernel/Memory/VirtualRange.h>
namespace Kernel
{
@@ -7,7 +7,6 @@
#include <kernel/Memory/ByteRingBuffer.h>
#include <kernel/Networking/NetworkInterface.h>
#include <kernel/Networking/NetworkSocket.h>
#include <kernel/Thread.h>
#include <kernel/ThreadBlocker.h>
namespace Kernel
@@ -6,6 +6,7 @@
#include <kernel/FS/Socket.h>
#include <kernel/FS/TmpFS/Inode.h>
#include <kernel/FS/VirtualFileSystem.h>
#include <kernel/Memory/VirtualRange.h>
#include <kernel/OpenFileDescriptorSet.h>
namespace Kernel
+2
View File
@@ -3,6 +3,8 @@
#include <BAN/UniqPtr.h>
#include <BAN/Vector.h>
#include <kernel/ACPI/AML/Node.h>
#include <kernel/InterruptNumbers.h>
#include <kernel/Interruptable.h>
#include <kernel/Memory/Types.h>
#include <sys/types.h>
+1 -2
View File
@@ -19,6 +19,7 @@
#include <poll.h>
#include <sys/banan-os.h>
#include <sys/epoll.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/socket.h>
@@ -26,8 +27,6 @@
#include <sys/time.h>
#include <termios.h>
struct epoll_event;
namespace Kernel
{
+10 -7
View File
@@ -1,17 +1,14 @@
#pragma once
#include <BAN/Array.h>
#include <BAN/Atomic.h>
#include <BAN/ForwardList.h>
#include <BAN/NoCopyMove.h>
#include <BAN/Math.h>
#include <kernel/API/SharedPage.h>
#include <kernel/Arch.h>
#include <kernel/GDT.h>
#include <kernel/IDT.h>
#include <kernel/InterruptStack.h>
#include <kernel/Memory/Types.h>
#include <kernel/ProcessorID.h>
#include <kernel/Scheduler.h>
namespace Kernel
{
@@ -22,6 +19,12 @@ namespace Kernel
Enabled,
};
class GDT;
class IDT;
class Scheduler;
class SchedulerQueueNode;
class Thread;
#if ARCH(x86_64) || ARCH(i686)
class Processor
{
@@ -51,8 +54,8 @@ namespace Kernel
union
{
TLBEntry flush_tlb;
SchedulerQueue::Node* new_thread;
SchedulerQueue::Node* unblock_thread;
SchedulerQueueNode* new_thread;
SchedulerQueueNode* unblock_thread;
bool dummy;
};
};
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once
#include <BAN/Atomic.h>
#include <kernel/ProcessorID.h>
#include <kernel/Lock/SpinLock.h>
namespace Kernel
{
@@ -1,6 +1,7 @@
#pragma once
#include <BAN/WeakPtr.h>
#include <kernel/Memory/VirtualRange.h>
#include <kernel/Terminal/TTY.h>
namespace Kernel
+3 -2
View File
@@ -5,8 +5,8 @@
#include <BAN/RefPtr.h>
#include <BAN/UniqPtr.h>
#include <kernel/InterruptStack.h>
#include <kernel/Lock/Mutex.h>
#include <kernel/Memory/VirtualRange.h>
#include <kernel/ThreadBlocker.h>
#include <LibELF/AuxiliaryVector.h>
@@ -18,6 +18,7 @@ namespace Kernel
class MemoryBackedRegion;
class Process;
class ThreadBlocker;
class Thread
{
@@ -191,7 +192,7 @@ namespace Kernel
vaddr_t m_fsbase { 0 };
vaddr_t m_gsbase { 0 };
SchedulerQueue::Node* m_scheduler_node { nullptr };
SchedulerQueueNode* m_scheduler_node { nullptr };
YieldRegisters m_yield_registers { };
+6 -4
View File
@@ -1,12 +1,14 @@
#pragma once
#include <BAN/Math.h>
#include <kernel/Lock/Mutex.h>
#include <kernel/Lock/SpinLock.h>
#include <kernel/Scheduler.h>
namespace Kernel
{
class SchedulerQueueNode;
class ThreadBlocker
{
public:
@@ -27,11 +29,11 @@ namespace Kernel
}
private:
void add_thread_to_block_queue(SchedulerQueue::Node*);
void remove_thread_from_block_queue(SchedulerQueue::Node*);
void add_thread_to_block_queue(SchedulerQueueNode*);
void remove_thread_from_block_queue(SchedulerQueueNode*);
private:
SchedulerQueue::Node* m_block_chain { nullptr };
SchedulerQueueNode* m_block_chain { nullptr };
SpinLock m_lock;
friend class Scheduler;
@@ -1,6 +1,5 @@
#pragma once
#include <kernel/Process.h>
#include <kernel/USB/Device.h>
namespace Kernel
+1
View File
@@ -8,6 +8,7 @@
#include <kernel/IO.h>
#include <kernel/Memory/PageTable.h>
#include <kernel/Process.h>
#include <kernel/Scheduler.h>
#include <kernel/Timer/Timer.h>
#define RSPD_SIZE 20
+2 -1
View File
@@ -1,5 +1,6 @@
#include <kernel/ACPI/BatterySystem.h>
#include <kernel/FS/DevFS//FileSystem.h>
#include <kernel/Device/Device.h>
#include <kernel/FS/DevFS/FileSystem.h>
#include <kernel/Timer/Timer.h>
namespace Kernel::ACPI
@@ -4,6 +4,8 @@
#include <kernel/ACPI/EmbeddedController.h>
#include <kernel/IO.h>
#include <kernel/Lock/LockGuard.h>
#include <kernel/Scheduler.h>
#include <kernel/Thread.h>
#include <kernel/Timer/Timer.h>
namespace Kernel::ACPI
+1
View File
@@ -4,6 +4,7 @@
#include <kernel/Device/DeviceNumbers.h>
#include <kernel/FS/DevFS/FileSystem.h>
#include <kernel/Lock/BlockableSpinLock.h>
#include <kernel/Thread.h>
#include <sys/ioctl.h>
#include <sys/sysmacros.h>
+1
View File
@@ -1,6 +1,7 @@
#include <kernel/Epoll.h>
#include <kernel/Lock/BlockableSpinLock.h>
#include <kernel/Lock/LockGuard.h>
#include <kernel/Thread.h>
#include <kernel/Timer/Timer.h>
namespace Kernel
+1
View File
@@ -1,5 +1,6 @@
#include <kernel/FS/EventFD.h>
#include <kernel/Lock/LockGuard.h>
#include <kernel/Thread.h>
#include <sys/epoll.h>
+1
View File
@@ -2,6 +2,7 @@
#include <BAN/Sort.h>
#include <kernel/FS/Ext2/FileSystem.h>
#include <kernel/Lock/LockGuard.h>
#include <kernel/Thread.h>
#define EXT2_DEBUG_PRINT 0
#define EXT2_VERIFY_INODE 0
+1
View File
@@ -1,3 +1,4 @@
#include <kernel/Device/Device.h>
#include <kernel/FS/FAT/FileSystem.h>
#include <kernel/Lock/LockGuard.h>
+1
View File
@@ -1,5 +1,6 @@
#include <BAN/Time.h>
#include <kernel/Device/Device.h>
#include <kernel/FS/FAT/FileSystem.h>
#include <kernel/FS/FAT/Inode.h>
+1
View File
@@ -1,6 +1,7 @@
#include <kernel/BootInfo.h>
#include <kernel/FS/ProcFS/FileSystem.h>
#include <kernel/FS/ProcFS/Inode.h>
#include <kernel/Process.h>
namespace Kernel
{
+1
View File
@@ -1,4 +1,5 @@
#include <kernel/FS/ProcFS/Inode.h>
#include <kernel/Process.h>
#include <ctype.h>
+2
View File
@@ -1,7 +1,9 @@
#include <BAN/Array.h>
#include <BAN/Errors.h>
#include <kernel/GDT.h>
#include <kernel/IDT.h>
#include <kernel/InterruptController.h>
#include <kernel/InterruptNumbers.h>
#include <kernel/InterruptStack.h>
#include <kernel/Memory/kmalloc.h>
#include <kernel/Panic.h>
+2
View File
@@ -4,7 +4,9 @@
#include <kernel/FS/DevFS/FileSystem.h>
#include <kernel/Input/InputDevice.h>
#include <kernel/Lock/BlockableSpinLock.h>
#include <kernel/Scheduler.h>
#include <kernel/Terminal/TTY.h>
#include <kernel/Thread.h>
#include <LibInput/Joystick.h>
#include <LibInput/KeyEvent.h>
+2
View File
@@ -8,6 +8,8 @@
#include <kernel/Input/PS2/Keyboard.h>
#include <kernel/Input/PS2/Mouse.h>
#include <kernel/IO.h>
#include <kernel/Scheduler.h>
#include <kernel/Thread.h>
#include <kernel/Timer/Timer.h>
namespace Kernel::Input
+134
View File
@@ -0,0 +1,134 @@
#include <kernel/Lock/Mutex.h>
#include <kernel/Thread.h>
namespace Kernel
{
bool Mutex::try_lock()
{
const auto tid = Thread::current_tid();
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
pid_t expected = -1;
if (!m_locker.compare_exchange(expected, tid))
return false;
ASSERT(m_lock_depth == 0);
if (tid)
Thread::current().add_mutex();
}
m_lock_depth++;
return true;
}
void Mutex::lock()
{
const auto tid = Thread::current_tid();
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
ASSERT(!tid || !Thread::current().has_spinlock());
pid_t expected = -1;
while (!m_locker.compare_exchange(expected, tid))
{
ASSERT(Processor::get_interrupt_state() == InterruptState::Enabled);
Processor::yield();
expected = -1;
}
ASSERT(m_lock_depth == 0);
if (tid)
Thread::current().add_mutex();
}
m_lock_depth++;
}
void Mutex::unlock()
{
const auto tid = Thread::current_tid();
ASSERT(m_locker == tid);
ASSERT(m_lock_depth > 0);
if (--m_lock_depth == 0)
{
m_locker = -1;
if (tid)
Thread::current().remove_mutex();
}
}
bool Mutex::is_locked_by_current_thread() const
{
return m_locker == Thread::current_tid();
}
bool PriorityMutex::try_lock()
{
const auto tid = Thread::current_tid();
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
bool has_priority = tid ? !Thread::current().is_userspace() : true;
pid_t expected = -1;
if (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(expected, tid))
return false;
if (has_priority)
m_queue_length++;
ASSERT(m_lock_depth == 0);
if (tid)
Thread::current().add_mutex();
}
m_lock_depth++;
return true;
}
void PriorityMutex::lock()
{
const auto tid = Thread::current_tid();
if (tid == m_locker)
ASSERT(m_lock_depth > 0);
else
{
ASSERT(!tid || !Thread::current().has_spinlock());
bool has_priority = tid ? !Thread::current().is_userspace() : true;
if (has_priority)
m_queue_length++;
pid_t expected = -1;
while (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(expected, tid))
{
ASSERT(Processor::get_interrupt_state() == InterruptState::Enabled);
Processor::yield();
expected = -1;
}
ASSERT(m_lock_depth == 0);
if (tid)
Thread::current().add_mutex();
}
m_lock_depth++;
}
void PriorityMutex::unlock()
{
const auto tid = Thread::current_tid();
ASSERT(m_locker == tid);
ASSERT(m_lock_depth > 0);
if (--m_lock_depth == 0)
{
bool has_priority = tid ? !Thread::current().is_userspace() : true;
if (has_priority)
m_queue_length--;
m_locker = -1;
if (tid)
Thread::current().remove_mutex();
}
}
bool PriorityMutex::is_locked_by_current_thread() const
{
return m_locker == Thread::current_tid();
}
}
+58
View File
@@ -0,0 +1,58 @@
#include <kernel/Lock/BlockableSpinLock.h>
#include <kernel/Lock/RWLock.h>
#include <kernel/Thread.h>
namespace Kernel
{
void RWLock::rd_lock()
{
SpinLockGuard _(m_lock);
while (m_writers_waiting > 0 || m_writer != -1)
{
BlockableSpinLock block(m_lock);
m_thread_blocker.block_indefinite(&block);
}
m_readers_active++;
}
void RWLock::rd_unlock()
{
SpinLockGuard _(m_lock);
if (--m_readers_active == 0)
m_thread_blocker.unblock();
}
void RWLock::wr_lock()
{
if (m_writer == Thread::current_tid())
{
m_writer_depth++;
return;
}
SpinLockGuard _(m_lock);
m_writers_waiting++;
while (m_readers_active > 0 || m_writer != -1)
{
BlockableSpinLock block(m_lock);
m_thread_blocker.block_indefinite(&block);
}
m_writers_waiting--;
m_writer = Thread::current_tid();
m_writer_depth = 1;
}
void RWLock::wr_unlock()
{
if (--m_writer_depth != 0)
return;
SpinLockGuard _(m_lock);
m_writer = -1;
m_thread_blocker.unblock();
}
}
+2
View File
@@ -6,6 +6,8 @@
#include <kernel/MMIO.h>
#include <kernel/Networking/E1000/E1000.h>
#include <kernel/Networking/NetworkManager.h>
#include <kernel/Scheduler.h>
#include <kernel/Thread.h>
namespace Kernel
{
+2
View File
@@ -1,6 +1,8 @@
#include <kernel/Lock/BlockableSpinLock.h>
#include <kernel/Networking/Loopback.h>
#include <kernel/Networking/NetworkManager.h>
#include <kernel/Scheduler.h>
#include <kernel/Thread.h>
namespace Kernel
{
@@ -2,6 +2,8 @@
#include <kernel/Networking/NetworkManager.h>
#include <kernel/Networking/RTL8169/Definitions.h>
#include <kernel/Networking/RTL8169/RTL8169.h>
#include <kernel/Scheduler.h>
#include <kernel/Thread.h>
#include <kernel/Timer/Timer.h>
namespace Kernel
+1
View File
@@ -3,6 +3,7 @@
#include <kernel/Networking/TCPSocket.h>
#include <kernel/Process.h>
#include <kernel/Random.h>
#include <kernel/Scheduler.h>
#include <kernel/Timer/Timer.h>
#include <fcntl.h>
+1
View File
@@ -1,4 +1,5 @@
#include <kernel/IDT.h>
#include <kernel/InterruptNumbers.h>
#include <kernel/IO.h>
#include <kernel/PIC.h>
+4
View File
@@ -1,8 +1,12 @@
#include <kernel/CPUID.h>
#include <kernel/GDT.h>
#include <kernel/IDT.h>
#include <kernel/InterruptController.h>
#include <kernel/IO.h>
#include <kernel/Memory/Heap.h>
#include <kernel/Memory/kmalloc.h>
#include <kernel/Processor.h>
#include <kernel/Scheduler.h>
#include <kernel/Terminal/TerminalDriver.h>
#include <kernel/Thread.h>
#include <kernel/Timer/Timer.h>
+1
View File
@@ -1,6 +1,7 @@
#include <BAN/Optional.h>
#include <BAN/Sort.h>
#include <kernel/APIC.h>
#include <kernel/GDT.h>
#include <kernel/InterruptController.h>
#include <kernel/Lock/Mutex.h>
#include <kernel/Process.h>
@@ -1,3 +1,4 @@
#include <kernel/Lock/BlockableSpinLock.h>
#include <kernel/Lock/LockGuard.h>
#include <kernel/Scheduler.h>
#include <kernel/Storage/ATA/AHCI/Controller.h>
@@ -2,6 +2,7 @@
#include <kernel/FS/DevFS/FileSystem.h>
#include <kernel/Lock/BlockableSpinLock.h>
#include <kernel/Terminal/PseudoTerminal.h>
#include <kernel/Thread.h>
#include <BAN/ScopeGuard.h>
+3 -2
View File
@@ -1,4 +1,5 @@
#include <kernel/Processor.h>
#include <kernel/Scheduler.h>
#include <kernel/SchedulerQueueNode.h>
#include <kernel/ThreadBlocker.h>
#include <kernel/Timer/Timer.h>
@@ -44,7 +45,7 @@ namespace Kernel
m_block_chain = nullptr;
}
void ThreadBlocker::add_thread_to_block_queue(SchedulerQueue::Node* node)
void ThreadBlocker::add_thread_to_block_queue(SchedulerQueueNode* node)
{
SpinLockGuard _(m_lock);
@@ -60,7 +61,7 @@ namespace Kernel
m_block_chain = node;
}
void ThreadBlocker::remove_thread_from_block_queue(SchedulerQueue::Node* node)
void ThreadBlocker::remove_thread_from_block_queue(SchedulerQueueNode* node)
{
SpinLockGuard _(m_lock);
+1
View File
@@ -6,6 +6,7 @@
#include <kernel/Memory/PageTable.h>
#include <kernel/MMIO.h>
#include <kernel/Processor.h>
#include <kernel/Scheduler.h>
#include <kernel/Timer/HPET.h>
#define HPET_PERIOD_MAX 0x05F5E100
+1
View File
@@ -2,6 +2,7 @@
#include <kernel/InterruptController.h>
#include <kernel/IO.h>
#include <kernel/Processor.h>
#include <kernel/Scheduler.h>
#include <kernel/Timer/PIT.h>
#define PIT_IRQ 0
+4 -2
View File
@@ -1,7 +1,9 @@
#include <BAN/ScopeGuard.h>
#include <kernel/Scheduler.h>
#include <kernel/Thread.h>
#include <kernel/Timer/Timer.h>
#include <kernel/USB/Hub/Definitions.h>
#include <kernel/USB/Hub/HubDriver.h>
#include <kernel/Timer/Timer.h>
namespace Kernel
{
@@ -192,7 +194,7 @@ namespace Kernel
auto result = m_device.send_request(request, m_data_region->paddr());
if (result.is_error() || result.value() != sizeof(USBHub::PortStatus))
{
dwarnln("Failed to get port {} status");
dwarnln("Failed to get port {} status", port_id);
continue;
}
+1
View File
@@ -3,6 +3,7 @@
#include <kernel/Lock/LockGuard.h>
#include <kernel/Process.h>
#include <kernel/Scheduler.h>
#include <kernel/Timer/Timer.h>
#include <kernel/USB/XHCI/Controller.h>
#include <kernel/USB/XHCI/Device.h>