summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-11-09 11:39:58 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2023-01-02 18:15:27 -0500
commita6a439243f3101e5d2f75f54b8aa6bc4c8b2e323 (patch)
tree6138d92caa93e67f63f0c6b20b3916224d9aae7b
parent363cc121462e452236623db44845329db3098fca (diff)
downloadserenity-a6a439243f3101e5d2f75f54b8aa6bc4c8b2e323.zip
Kernel: Turn lock ranks into template parameters
This step would ideally not have been necessary (increases amount of refactoring and templates necessary, which in turn increases build times), but it gives us a couple of nice properties: - SpinlockProtected inside Singleton (a very common combination) can now obtain any lock rank just via the template parameter. It was not previously possible to do this with SingletonInstanceCreator magic. - SpinlockProtected's lock rank is now mandatory; this is the majority of cases and allows us to see where we're still missing proper ranks. - The type already informs us what lock rank a lock has, which aids code readability and (possibly, if gdb cooperates) lock mismatch debugging. - The rank of a lock can no longer be dynamic, which is not something we wanted in the first place (or made use of). Locks randomly changing their rank sounds like a disaster waiting to happen. - In some places, we might be able to statically check that locks are taken in the right order (with the right lock rank checking implementation) as rank information is fully statically known. This refactoring even more exposes the fact that Mutex has no lock rank capabilites, which is not fixed here.
-rw-r--r--AK/Singleton.h9
-rw-r--r--Kernel/Arch/x86_64/ISABus/I8042Controller.h2
-rw-r--r--Kernel/Arch/x86_64/PageDirectory.cpp2
-rw-r--r--Kernel/Arch/x86_64/VGA/IOArbiter.h2
-rw-r--r--Kernel/Bus/PCI/Access.h8
-rw-r--r--Kernel/Bus/PCI/Controller/VolumeManagementDevice.h2
-rw-r--r--Kernel/Bus/USB/UHCI/UHCIController.cpp2
-rw-r--r--Kernel/Bus/USB/UHCI/UHCIController.h4
-rw-r--r--Kernel/Bus/USB/UHCI/UHCIDescriptorPool.h3
-rw-r--r--Kernel/Bus/VirtIO/Queue.h4
-rw-r--r--Kernel/CMakeLists.txt1
-rw-r--r--Kernel/Coredump.cpp4
-rw-r--r--Kernel/Coredump.h2
-rw-r--r--Kernel/Devices/AsyncDeviceRequest.h4
-rw-r--r--Kernel/Devices/Audio/AC97.h2
-rw-r--r--Kernel/Devices/ConsoleDevice.cpp2
-rw-r--r--Kernel/Devices/ConsoleDevice.h2
-rw-r--r--Kernel/Devices/Device.h2
-rw-r--r--Kernel/Devices/DeviceManagement.h4
-rw-r--r--Kernel/Devices/HID/HIDManagement.h6
-rw-r--r--Kernel/Devices/HID/KeyboardDevice.h2
-rw-r--r--Kernel/Devices/HID/MouseDevice.h2
-rw-r--r--Kernel/Devices/KCOVInstance.h4
-rw-r--r--Kernel/Devices/SerialDevice.h2
-rw-r--r--Kernel/FileSystem/Custody.cpp4
-rw-r--r--Kernel/FileSystem/Custody.h2
-rw-r--r--Kernel/FileSystem/FileSystem.h4
-rw-r--r--Kernel/FileSystem/Inode.cpp4
-rw-r--r--Kernel/FileSystem/Inode.h6
-rw-r--r--Kernel/FileSystem/Mount.cpp4
-rw-r--r--Kernel/FileSystem/Mount.h2
-rw-r--r--Kernel/FileSystem/OpenFileDescription.h2
-rw-r--r--Kernel/FileSystem/Plan9FS/FileSystem.h6
-rw-r--r--Kernel/FileSystem/SysFS/Component.cpp2
-rw-r--r--Kernel/FileSystem/SysFS/Component.h4
-rw-r--r--Kernel/FileSystem/SysFS/Registry.h2
-rw-r--r--Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h2
-rw-r--r--Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/CapsLockRemap.h2
-rw-r--r--Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/DumpKmallocStack.h2
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.cpp1
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.h8
-rw-r--r--Kernel/Forward.h4
-rw-r--r--Kernel/Graphics/Console/BootFramebufferConsole.h2
-rw-r--r--Kernel/Graphics/Console/GenericFramebufferConsole.h2
-rw-r--r--Kernel/Graphics/Console/VGATextModeConsole.h2
-rw-r--r--Kernel/Graphics/DisplayConnector.h6
-rw-r--r--Kernel/Graphics/GraphicsManagement.h2
-rw-r--r--Kernel/Graphics/Intel/NativeDisplayConnector.h2
-rw-r--r--Kernel/Graphics/VMWare/GraphicsAdapter.h4
-rw-r--r--Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h4
-rw-r--r--Kernel/Heap/kmalloc.cpp2
-rw-r--r--Kernel/Jail.h4
-rw-r--r--Kernel/JailManagement.h2
-rw-r--r--Kernel/Locking/Mutex.cpp2
-rw-r--r--Kernel/Locking/Mutex.h7
-rw-r--r--Kernel/Locking/Spinlock.cpp66
-rw-r--r--Kernel/Locking/Spinlock.h65
-rw-r--r--Kernel/Locking/SpinlockProtected.h12
-rw-r--r--Kernel/Memory/AnonymousVMObject.h2
-rw-r--r--Kernel/Memory/MemoryManager.cpp1
-rw-r--r--Kernel/Memory/MemoryManager.h4
-rw-r--r--Kernel/Memory/PageDirectory.h4
-rw-r--r--Kernel/Memory/Region.cpp2
-rw-r--r--Kernel/Memory/Region.h3
-rw-r--r--Kernel/Memory/RingBuffer.h4
-rw-r--r--Kernel/Memory/SharedFramebufferVMObject.h2
-rw-r--r--Kernel/Memory/VMObject.cpp4
-rw-r--r--Kernel/Memory/VMObject.h4
-rw-r--r--Kernel/Net/NetworkAdapter.h2
-rw-r--r--Kernel/Net/NetworkingManagement.h2
-rw-r--r--Kernel/Net/Routing.cpp8
-rw-r--r--Kernel/Net/Routing.h4
-rw-r--r--Kernel/Process.cpp16
-rw-r--r--Kernel/Process.h32
-rw-r--r--Kernel/ProcessExposed.cpp2
-rw-r--r--Kernel/ProcessGroup.cpp4
-rw-r--r--Kernel/ProcessGroup.h2
-rw-r--r--Kernel/Random.h4
-rw-r--r--Kernel/Scheduler.cpp6
-rw-r--r--Kernel/Scheduler.h2
-rw-r--r--Kernel/Storage/ATA/AHCI/Controller.h2
-rw-r--r--Kernel/Storage/ATA/AHCI/Port.h2
-rw-r--r--Kernel/Storage/ATA/ATAPort.h2
-rw-r--r--Kernel/Storage/NVMe/NVMeQueue.h6
-rw-r--r--Kernel/Syscalls/futex.cpp2
-rw-r--r--Kernel/TTY/ConsoleManagement.h6
-rw-r--r--Kernel/TTY/PTYMultiplexer.h2
-rw-r--r--Kernel/TTY/SlavePTY.cpp4
-rw-r--r--Kernel/TTY/SlavePTY.h2
-rw-r--r--Kernel/Thread.cpp6
-rw-r--r--Kernel/Thread.h18
-rw-r--r--Kernel/TimerQueue.cpp2
-rw-r--r--Kernel/WorkQueue.h2
-rw-r--r--Kernel/kprintf.cpp2
94 files changed, 235 insertions, 259 deletions
diff --git a/AK/Singleton.h b/AK/Singleton.h
index ed104befd0..626ba07b91 100644
--- a/AK/Singleton.h
+++ b/AK/Singleton.h
@@ -39,12 +39,11 @@ struct SingletonInstanceCreator {
#ifdef KERNEL
-// FIXME: Find a nice way of injecting the lock rank into the singleton.
-template<typename T>
-struct SingletonInstanceCreator<Kernel::SpinlockProtected<T>> {
- static Kernel::SpinlockProtected<T>* create()
+template<typename T, Kernel::LockRank Rank>
+struct SingletonInstanceCreator<Kernel::SpinlockProtected<T, Rank>> {
+ static Kernel::SpinlockProtected<T, Rank>* create()
{
- return new Kernel::SpinlockProtected<T> { Kernel::LockRank::None };
+ return new Kernel::SpinlockProtected<T, Rank> {};
}
};
#endif
diff --git a/Kernel/Arch/x86_64/ISABus/I8042Controller.h b/Kernel/Arch/x86_64/ISABus/I8042Controller.h
index 997cf4517d..e62b5517a3 100644
--- a/Kernel/Arch/x86_64/ISABus/I8042Controller.h
+++ b/Kernel/Arch/x86_64/ISABus/I8042Controller.h
@@ -153,7 +153,7 @@ private:
void do_write(u8 port, u8 data);
u8 do_read(u8 port);
- Spinlock m_lock { LockRank::None };
+ Spinlock<LockRank::None> m_lock {};
bool m_first_port_available { false };
bool m_second_port_available { false };
bool m_is_dual_channel { false };
diff --git a/Kernel/Arch/x86_64/PageDirectory.cpp b/Kernel/Arch/x86_64/PageDirectory.cpp
index 1efe016508..89bfc63813 100644
--- a/Kernel/Arch/x86_64/PageDirectory.cpp
+++ b/Kernel/Arch/x86_64/PageDirectory.cpp
@@ -12,7 +12,7 @@
namespace Kernel::Memory {
struct CR3Map {
- SpinlockProtected<IntrusiveRedBlackTree<&PageDirectory::m_tree_node>> map { LockRank::None };
+ SpinlockProtected<IntrusiveRedBlackTree<&PageDirectory::m_tree_node>, LockRank::None> map {};
};
static Singleton<CR3Map> s_cr3_map;
diff --git a/Kernel/Arch/x86_64/VGA/IOArbiter.h b/Kernel/Arch/x86_64/VGA/IOArbiter.h
index 711f8324d8..70bcf4dc78 100644
--- a/Kernel/Arch/x86_64/VGA/IOArbiter.h
+++ b/Kernel/Arch/x86_64/VGA/IOArbiter.h
@@ -33,7 +33,7 @@ private:
void disable_vga_text_mode_console_cursor();
void enable_vga_text_mode_console_cursor();
- RecursiveSpinlock m_main_vga_lock { LockRank::None };
+ RecursiveSpinlock<LockRank::None> m_main_vga_lock {};
bool m_vga_access_is_disabled { false };
};
diff --git a/Kernel/Bus/PCI/Access.h b/Kernel/Bus/PCI/Access.h
index 81959c8750..e0fd8a924b 100644
--- a/Kernel/Bus/PCI/Access.h
+++ b/Kernel/Bus/PCI/Access.h
@@ -41,8 +41,8 @@ public:
u32 read32_field(Address address, u32 field);
DeviceIdentifier get_device_identifier(Address address) const;
- Spinlock const& scan_lock() const { return m_scan_lock; }
- RecursiveSpinlock const& access_lock() const { return m_access_lock; }
+ Spinlock<LockRank::None> const& scan_lock() const { return m_scan_lock; }
+ RecursiveSpinlock<LockRank::None> const& access_lock() const { return m_access_lock; }
ErrorOr<void> add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr<HostController>, Function<void(DeviceIdentifier const&)> callback);
@@ -57,8 +57,8 @@ private:
Vector<Capability> get_capabilities(Address);
Optional<u8> get_capabilities_pointer(Address address);
- mutable RecursiveSpinlock m_access_lock { LockRank::None };
- mutable Spinlock m_scan_lock { LockRank::None };
+ mutable RecursiveSpinlock<LockRank::None> m_access_lock {};
+ mutable Spinlock<LockRank::None> m_scan_lock {};
HashMap<u32, NonnullOwnPtr<PCI::HostController>> m_host_controllers;
Vector<DeviceIdentifier> m_device_identifiers;
diff --git a/Kernel/Bus/PCI/Controller/VolumeManagementDevice.h b/Kernel/Bus/PCI/Controller/VolumeManagementDevice.h
index a5baad70d7..5e016601ff 100644
--- a/Kernel/Bus/PCI/Controller/VolumeManagementDevice.h
+++ b/Kernel/Bus/PCI/Controller/VolumeManagementDevice.h
@@ -29,7 +29,7 @@ private:
// Note: All read and writes must be done with a spinlock because
// Linux says that CPU might deadlock otherwise if access is not serialized.
- Spinlock m_config_lock { LockRank::None };
+ Spinlock<LockRank::None> m_config_lock {};
};
}
diff --git a/Kernel/Bus/USB/UHCI/UHCIController.cpp b/Kernel/Bus/USB/UHCI/UHCIController.cpp
index 17e0df4344..d9867968de 100644
--- a/Kernel/Bus/USB/UHCI/UHCIController.cpp
+++ b/Kernel/Bus/USB/UHCI/UHCIController.cpp
@@ -90,8 +90,6 @@ UNMAP_AFTER_INIT UHCIController::UHCIController(PCI::DeviceIdentifier const& pci
: PCI::Device(pci_device_identifier.address())
, IRQHandler(pci_device_identifier.interrupt_line().value())
, m_registers_io_window(move(registers_io_window))
- , m_async_lock(LockRank::None)
- , m_schedule_lock(LockRank::None)
{
}
diff --git a/Kernel/Bus/USB/UHCI/UHCIController.h b/Kernel/Bus/USB/UHCI/UHCIController.h
index ccbd218e6f..1b45461cd5 100644
--- a/Kernel/Bus/USB/UHCI/UHCIController.h
+++ b/Kernel/Bus/USB/UHCI/UHCIController.h
@@ -100,8 +100,8 @@ private:
NonnullOwnPtr<IOWindow> m_registers_io_window;
- Spinlock m_async_lock;
- Spinlock m_schedule_lock;
+ Spinlock<LockRank::None> m_async_lock {};
+ Spinlock<LockRank::None> m_schedule_lock {};
OwnPtr<UHCIRootHub> m_root_hub;
OwnPtr<UHCIDescriptorPool<QueueHead>> m_queue_head_pool;
diff --git a/Kernel/Bus/USB/UHCI/UHCIDescriptorPool.h b/Kernel/Bus/USB/UHCI/UHCIDescriptorPool.h
index dc9b5d87de..e1dbb41e57 100644
--- a/Kernel/Bus/USB/UHCI/UHCIDescriptorPool.h
+++ b/Kernel/Bus/USB/UHCI/UHCIDescriptorPool.h
@@ -70,7 +70,6 @@ private:
UHCIDescriptorPool(NonnullOwnPtr<Memory::Region> pool_memory_block, StringView name)
: m_pool_name(name)
, m_pool_region(move(pool_memory_block))
- , m_pool_lock(LockRank::None)
{
// Go through the number of descriptors to create in the pool, and create a virtual/physical address mapping
for (size_t i = 0; i < PAGE_SIZE / sizeof(T); i++) {
@@ -84,7 +83,7 @@ private:
StringView m_pool_name; // Name of this pool
NonnullOwnPtr<Memory::Region> m_pool_region; // Memory region where descriptors actually reside
Stack<T*, PAGE_SIZE / sizeof(T)> m_free_descriptor_stack; // Stack of currently free descriptor pointers
- Spinlock m_pool_lock;
+ Spinlock<LockRank::None> m_pool_lock;
};
}
diff --git a/Kernel/Bus/VirtIO/Queue.h b/Kernel/Bus/VirtIO/Queue.h
index 6563779866..26edc622f3 100644
--- a/Kernel/Bus/VirtIO/Queue.h
+++ b/Kernel/Bus/VirtIO/Queue.h
@@ -47,7 +47,7 @@ public:
QueueChain pop_used_buffer_chain(size_t& used);
void discard_used_buffers();
- Spinlock& lock() { return m_lock; }
+ Spinlock<LockRank::None>& lock() { return m_lock; }
bool should_notify() const;
@@ -96,7 +96,7 @@ private:
QueueDriver* m_driver { nullptr };
QueueDevice* m_device { nullptr };
NonnullOwnPtr<Memory::Region> m_queue_region;
- Spinlock m_lock { LockRank::None };
+ Spinlock<LockRank::None> m_lock {};
friend class QueueChain;
};
diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt
index a14c4cc833..fc1ff6795c 100644
--- a/Kernel/CMakeLists.txt
+++ b/Kernel/CMakeLists.txt
@@ -236,7 +236,6 @@ set(KERNEL_SOURCES
MiniStdLib.cpp
Locking/LockRank.cpp
Locking/Mutex.cpp
- Locking/Spinlock.cpp
Net/Intel/E1000ENetworkAdapter.cpp
Net/Intel/E1000NetworkAdapter.cpp
Net/NE2000/NetworkAdapter.cpp
diff --git a/Kernel/Coredump.cpp b/Kernel/Coredump.cpp
index 3ffd60b133..ea36e60270 100644
--- a/Kernel/Coredump.cpp
+++ b/Kernel/Coredump.cpp
@@ -23,11 +23,11 @@
#define INCLUDE_USERSPACE_HEAP_MEMORY_IN_COREDUMPS 0
-static Singleton<SpinlockProtected<OwnPtr<KString>>> s_coredump_directory_path;
+static Singleton<SpinlockProtected<OwnPtr<KString>, LockRank::None>> s_coredump_directory_path;
namespace Kernel {
-SpinlockProtected<OwnPtr<KString>>& Coredump::directory_path()
+SpinlockProtected<OwnPtr<KString>, LockRank::None>& Coredump::directory_path()
{
return s_coredump_directory_path;
}
diff --git a/Kernel/Coredump.h b/Kernel/Coredump.h
index d1acea68d8..2b9f7127f7 100644
--- a/Kernel/Coredump.h
+++ b/Kernel/Coredump.h
@@ -19,7 +19,7 @@ namespace Kernel {
class Coredump {
public:
static ErrorOr<NonnullOwnPtr<Coredump>> try_create(NonnullLockRefPtr<Process>, StringView output_path);
- static SpinlockProtected<OwnPtr<KString>>& directory_path();
+ static SpinlockProtected<OwnPtr<KString>, LockRank::None>& directory_path();
~Coredump() = default;
ErrorOr<void> write();
diff --git a/Kernel/Devices/AsyncDeviceRequest.h b/Kernel/Devices/AsyncDeviceRequest.h
index 79c94f2e86..449b2f9d84 100644
--- a/Kernel/Devices/AsyncDeviceRequest.h
+++ b/Kernel/Devices/AsyncDeviceRequest.h
@@ -62,7 +62,7 @@ public:
[[nodiscard]] RequestWaitResult wait(Time* = nullptr);
- void do_start(SpinlockLocker<Spinlock>&& requests_lock)
+ void do_start(SpinlockLocker<Spinlock<LockRank::None>>&& requests_lock)
{
if (is_completed_result(m_result))
return;
@@ -151,7 +151,7 @@ private:
WaitQueue m_queue;
NonnullLockRefPtr<Process> m_process;
void* m_private { nullptr };
- mutable Spinlock m_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_lock {};
};
}
diff --git a/Kernel/Devices/Audio/AC97.h b/Kernel/Devices/Audio/AC97.h
index 9ad53a8d18..092b9115ba 100644
--- a/Kernel/Devices/Audio/AC97.h
+++ b/Kernel/Devices/Audio/AC97.h
@@ -147,7 +147,7 @@ private:
NonnullOwnPtr<IOWindow> m_channel_io_window;
PCI::Address m_device_pci_address;
- SpinlockProtected<bool> m_dma_running { LockRank::None, false };
+ SpinlockProtected<bool, LockRank::None> m_dma_running { false };
StringView m_name;
};
diff --git a/Kernel/Devices/ConsoleDevice.cpp b/Kernel/Devices/ConsoleDevice.cpp
index 92044f852b..c68c8fe1ff 100644
--- a/Kernel/Devices/ConsoleDevice.cpp
+++ b/Kernel/Devices/ConsoleDevice.cpp
@@ -16,7 +16,7 @@
namespace Kernel {
-Spinlock g_console_lock { LockRank::None };
+Spinlock<LockRank::None> g_console_lock {};
UNMAP_AFTER_INIT NonnullLockRefPtr<ConsoleDevice> ConsoleDevice::must_create()
{
diff --git a/Kernel/Devices/ConsoleDevice.h b/Kernel/Devices/ConsoleDevice.h
index 3800a58baa..d9eb6377f7 100644
--- a/Kernel/Devices/ConsoleDevice.h
+++ b/Kernel/Devices/ConsoleDevice.h
@@ -12,7 +12,7 @@
namespace Kernel {
-extern Spinlock g_console_lock;
+extern Spinlock<LockRank::None> g_console_lock;
class ConsoleDevice final : public CharacterDevice {
friend class DeviceManagement;
diff --git a/Kernel/Devices/Device.h b/Kernel/Devices/Device.h
index dcfb263fd7..4a1e51c219 100644
--- a/Kernel/Devices/Device.h
+++ b/Kernel/Devices/Device.h
@@ -90,7 +90,7 @@ private:
State m_state { State::Normal };
- Spinlock m_requests_lock { LockRank::None };
+ Spinlock<LockRank::None> m_requests_lock {};
DoublyLinkedList<LockRefPtr<AsyncDeviceRequest>> m_requests;
protected:
diff --git a/Kernel/Devices/DeviceManagement.h b/Kernel/Devices/DeviceManagement.h
index 4d4d71cca9..d96a4d2a93 100644
--- a/Kernel/Devices/DeviceManagement.h
+++ b/Kernel/Devices/DeviceManagement.h
@@ -74,9 +74,9 @@ private:
LockRefPtr<ConsoleDevice> m_console_device;
LockRefPtr<DeviceControlDevice> m_device_control_device;
// FIXME: Once we have a singleton for managing many sound cards, remove this from here
- SpinlockProtected<HashMap<u64, Device*>> m_devices { LockRank::None };
+ SpinlockProtected<HashMap<u64, Device*>, LockRank::None> m_devices {};
- mutable Spinlock m_event_queue_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_event_queue_lock {};
CircularQueue<DeviceEvent, 100> m_event_queue;
};
diff --git a/Kernel/Devices/HID/HIDManagement.h b/Kernel/Devices/HID/HIDManagement.h
index c63c868cc4..bf1d17f5b1 100644
--- a/Kernel/Devices/HID/HIDManagement.h
+++ b/Kernel/Devices/HID/HIDManagement.h
@@ -47,7 +47,7 @@ public:
Keyboard::CharacterMapData character_map;
};
- SpinlockProtected<KeymapData>& keymap_data() { return m_keymap_data; }
+ SpinlockProtected<KeymapData, LockRank::None>& keymap_data() { return m_keymap_data; }
u32 get_char_from_character_map(KeyEvent) const;
@@ -58,7 +58,7 @@ private:
size_t generate_minor_device_number_for_mouse();
size_t generate_minor_device_number_for_keyboard();
- SpinlockProtected<KeymapData> m_keymap_data { LockRank::None };
+ SpinlockProtected<KeymapData, LockRank::None> m_keymap_data {};
size_t m_mouse_minor_number { 0 };
size_t m_keyboard_minor_number { 0 };
KeyboardClient* m_client { nullptr };
@@ -66,7 +66,7 @@ private:
LockRefPtr<I8042Controller> m_i8042_controller;
#endif
NonnullLockRefPtrVector<HIDDevice> m_hid_devices;
- Spinlock m_client_lock { LockRank::None };
+ Spinlock<LockRank::None> m_client_lock {};
};
class KeyboardClient {
diff --git a/Kernel/Devices/HID/KeyboardDevice.h b/Kernel/Devices/HID/KeyboardDevice.h
index 95152f4252..85896e9bf1 100644
--- a/Kernel/Devices/HID/KeyboardDevice.h
+++ b/Kernel/Devices/HID/KeyboardDevice.h
@@ -45,7 +45,7 @@ public:
protected:
KeyboardDevice();
- mutable Spinlock m_queue_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_queue_lock {};
CircularQueue<Event, 16> m_queue;
// ^CharacterDevice
virtual StringView class_name() const override { return "KeyboardDevice"sv; }
diff --git a/Kernel/Devices/HID/MouseDevice.h b/Kernel/Devices/HID/MouseDevice.h
index 68f57c66dc..f32fa11d9f 100644
--- a/Kernel/Devices/HID/MouseDevice.h
+++ b/Kernel/Devices/HID/MouseDevice.h
@@ -35,7 +35,7 @@ protected:
// ^CharacterDevice
virtual StringView class_name() const override { return "MouseDevice"sv; }
- mutable Spinlock m_queue_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_queue_lock {};
CircularQueue<MousePacket, 100> m_queue;
};
diff --git a/Kernel/Devices/KCOVInstance.h b/Kernel/Devices/KCOVInstance.h
index 6958de0b8a..a5c97cca08 100644
--- a/Kernel/Devices/KCOVInstance.h
+++ b/Kernel/Devices/KCOVInstance.h
@@ -46,7 +46,7 @@ public:
Memory::VMObject* vmobject() { return m_vmobject; }
- Spinlock& spinlock() { return m_lock; }
+ Spinlock<LockRank::None>& spinlock() { return m_lock; }
private:
ProcessID m_pid { 0 };
@@ -58,7 +58,7 @@ private:
// Here to ensure it's not garbage collected at the end of open()
OwnPtr<Memory::Region> m_kernel_region;
- Spinlock m_lock { LockRank::None };
+ Spinlock<LockRank::None> m_lock {};
};
}
diff --git a/Kernel/Devices/SerialDevice.h b/Kernel/Devices/SerialDevice.h
index 11448aca61..3d1866dd95 100644
--- a/Kernel/Devices/SerialDevice.h
+++ b/Kernel/Devices/SerialDevice.h
@@ -130,7 +130,7 @@ private:
bool m_break_enable { false };
u8 m_modem_control { 0 };
bool m_last_put_char_was_carriage_return { false };
- Spinlock m_serial_lock { LockRank::None };
+ Spinlock<LockRank::None> m_serial_lock {};
};
}
diff --git a/Kernel/FileSystem/Custody.cpp b/Kernel/FileSystem/Custody.cpp
index 0c40a26197..bf94934413 100644
--- a/Kernel/FileSystem/Custody.cpp
+++ b/Kernel/FileSystem/Custody.cpp
@@ -14,9 +14,9 @@
namespace Kernel {
-static Singleton<SpinlockProtected<Custody::AllCustodiesList>> s_all_instances;
+static Singleton<SpinlockProtected<Custody::AllCustodiesList, LockRank::None>> s_all_instances;
-SpinlockProtected<Custody::AllCustodiesList>& Custody::all_instances()
+SpinlockProtected<Custody::AllCustodiesList, LockRank::None>& Custody::all_instances()
{
return s_all_instances;
}
diff --git a/Kernel/FileSystem/Custody.h b/Kernel/FileSystem/Custody.h
index f72cf071c6..8d6edba176 100644
--- a/Kernel/FileSystem/Custody.h
+++ b/Kernel/FileSystem/Custody.h
@@ -44,7 +44,7 @@ private:
public:
using AllCustodiesList = IntrusiveList<&Custody::m_all_custodies_list_node>;
- static SpinlockProtected<Custody::AllCustodiesList>& all_instances();
+ static SpinlockProtected<Custody::AllCustodiesList, LockRank::None>& all_instances();
};
}
diff --git a/Kernel/FileSystem/FileSystem.h b/Kernel/FileSystem/FileSystem.h
index 39ae416ca6..4c6c1253c7 100644
--- a/Kernel/FileSystem/FileSystem.h
+++ b/Kernel/FileSystem/FileSystem.h
@@ -61,7 +61,7 @@ public:
// Converts file types that are used internally by the filesystem to DT_* types
virtual u8 internal_file_type_to_directory_entry_type(DirectoryEntryView const& entry) const { return entry.file_type; }
- SpinlockProtected<size_t>& mounted_count(Badge<VirtualFileSystem>) { return m_attach_count; }
+ SpinlockProtected<size_t, LockRank::FileSystem>& mounted_count(Badge<VirtualFileSystem>) { return m_attach_count; }
protected:
FileSystem();
@@ -79,7 +79,7 @@ private:
size_t m_fragment_size { 0 };
bool m_readonly { false };
- SpinlockProtected<size_t> m_attach_count { LockRank::FileSystem, 0 };
+ SpinlockProtected<size_t, LockRank::FileSystem> m_attach_count { 0 };
IntrusiveListNode<FileSystem> m_file_system_node;
};
diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp
index a5581b323d..e6b8f1ef14 100644
--- a/Kernel/FileSystem/Inode.cpp
+++ b/Kernel/FileSystem/Inode.cpp
@@ -22,9 +22,9 @@
namespace Kernel {
-static Singleton<SpinlockProtected<Inode::AllInstancesList>> s_all_instances;
+static Singleton<SpinlockProtected<Inode::AllInstancesList, LockRank::None>> s_all_instances;
-SpinlockProtected<Inode::AllInstancesList>& Inode::all_instances()
+SpinlockProtected<Inode::AllInstancesList, LockRank::None>& Inode::all_instances()
{
return s_all_instances;
}
diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h
index cafa6630d4..c954de927a 100644
--- a/Kernel/FileSystem/Inode.h
+++ b/Kernel/FileSystem/Inode.h
@@ -132,7 +132,7 @@ private:
InodeIndex m_index { 0 };
LockWeakPtr<Memory::SharedInodeVMObject> m_shared_vmobject;
LockRefPtr<LocalSocket> m_bound_socket;
- SpinlockProtected<HashTable<InodeWatcher*>> m_watchers { LockRank::None };
+ SpinlockProtected<HashTable<InodeWatcher*>, LockRank::None> m_watchers {};
bool m_metadata_dirty { false };
LockRefPtr<FIFO> m_fifo;
IntrusiveListNode<Inode> m_inode_list_node;
@@ -146,11 +146,11 @@ private:
};
Thread::FlockBlockerSet m_flock_blocker_set;
- SpinlockProtected<Vector<Flock>> m_flocks { LockRank::None };
+ SpinlockProtected<Vector<Flock>, LockRank::None> m_flocks {};
public:
using AllInstancesList = IntrusiveList<&Inode::m_inode_list_node>;
- static SpinlockProtected<Inode::AllInstancesList>& all_instances();
+ static SpinlockProtected<Inode::AllInstancesList, LockRank::None>& all_instances();
};
}
diff --git a/Kernel/FileSystem/Mount.cpp b/Kernel/FileSystem/Mount.cpp
index 733147d746..b123b78ddc 100644
--- a/Kernel/FileSystem/Mount.cpp
+++ b/Kernel/FileSystem/Mount.cpp
@@ -14,7 +14,7 @@ namespace Kernel {
Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags)
: m_guest(guest_fs.root_inode())
, m_guest_fs(guest_fs)
- , m_host_custody(LockRank::None, host_custody)
+ , m_host_custody(host_custody)
, m_flags(flags)
{
}
@@ -22,7 +22,7 @@ Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags)
Mount::Mount(Inode& source, Custody& host_custody, int flags)
: m_guest(source)
, m_guest_fs(source.fs())
- , m_host_custody(LockRank::None, host_custody)
+ , m_host_custody(host_custody)
, m_flags(flags)
{
}
diff --git a/Kernel/FileSystem/Mount.h b/Kernel/FileSystem/Mount.h
index 6d4dc6c608..d0676a797e 100644
--- a/Kernel/FileSystem/Mount.h
+++ b/Kernel/FileSystem/Mount.h
@@ -40,7 +40,7 @@ public:
private:
NonnullLockRefPtr<Inode> m_guest;
NonnullLockRefPtr<FileSystem> m_guest_fs;
- SpinlockProtected<RefPtr<Custody>> m_host_custody;
+ SpinlockProtected<RefPtr<Custody>, LockRank::None> m_host_custody;
int m_flags;
IntrusiveListNode<Mount> m_vfs_list_node;
diff --git a/Kernel/FileSystem/OpenFileDescription.h b/Kernel/FileSystem/OpenFileDescription.h
index bb6edce3d9..c7972c1d3f 100644
--- a/Kernel/FileSystem/OpenFileDescription.h
+++ b/Kernel/FileSystem/OpenFileDescription.h
@@ -157,6 +157,6 @@ private:
FIFO::Direction fifo_direction : 2 { FIFO::Direction::Neither };
};
- SpinlockProtected<State> m_state { LockRank::None };
+ SpinlockProtected<State, LockRank::None> m_state {};
};
}
diff --git a/Kernel/FileSystem/Plan9FS/FileSystem.h b/Kernel/FileSystem/Plan9FS/FileSystem.h
index 1f5c4af322..3b4ee0c0cc 100644
--- a/Kernel/FileSystem/Plan9FS/FileSystem.h
+++ b/Kernel/FileSystem/Plan9FS/FileSystem.h
@@ -63,11 +63,11 @@ private:
private:
Plan9FS& m_fs;
- mutable Spinlock m_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_lock {};
};
struct ReceiveCompletion final : public AtomicRefCounted<ReceiveCompletion> {
- mutable Spinlock lock { LockRank::None };
+ mutable Spinlock<LockRank::None> lock {};
bool completed { false };
const u16 tag;
OwnPtr<Plan9FSMessage> message;
@@ -136,7 +136,7 @@ private:
Plan9FSBlockerSet m_completion_blocker;
HashMap<u16, NonnullLockRefPtr<ReceiveCompletion>> m_completions;
- Spinlock m_thread_lock { LockRank::None };
+ Spinlock<LockRank::None> m_thread_lock {};
LockRefPtr<Thread> m_thread;
Atomic<bool> m_thread_running { false };
Atomic<bool, AK::MemoryOrder::memory_order_relaxed> m_thread_shutdown { false };
diff --git a/Kernel/FileSystem/SysFS/Component.cpp b/Kernel/FileSystem/SysFS/Component.cpp
index a79bf06200..274216718f 100644
--- a/Kernel/FileSystem/SysFS/Component.cpp
+++ b/Kernel/FileSystem/SysFS/Component.cpp
@@ -13,7 +13,7 @@
namespace Kernel {
-static Spinlock s_index_lock { LockRank::None };
+static Spinlock<LockRank::None> s_index_lock {};
static InodeIndex s_next_inode_index { 0 };
static size_t allocate_inode_index()
diff --git a/Kernel/FileSystem/SysFS/Component.h b/Kernel/FileSystem/SysFS/Component.h
index 4b18eeaf88..3f9b5643f5 100644
--- a/Kernel/FileSystem/SysFS/Component.h
+++ b/Kernel/FileSystem/SysFS/Component.h
@@ -80,14 +80,14 @@ public:
virtual ErrorOr<NonnullLockRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
- using ChildList = SpinlockProtected<IntrusiveList<&SysFSComponent::m_list_node>>;
+ using ChildList = SpinlockProtected<IntrusiveList<&SysFSComponent::m_list_node>, LockRank::None>;
protected:
virtual bool is_root_directory() const { return false; }
SysFSDirectory() {};
explicit SysFSDirectory(SysFSDirectory const& parent_directory);
- ChildList m_child_components { LockRank::None };
+ ChildList m_child_components {};
};
}
diff --git a/Kernel/FileSystem/SysFS/Registry.h b/Kernel/FileSystem/SysFS/Registry.h
index c0113eb29d..360e29a5a5 100644
--- a/Kernel/FileSystem/SysFS/Registry.h
+++ b/Kernel/FileSystem/SysFS/Registry.h
@@ -32,7 +32,7 @@ public:
private:
NonnullLockRefPtr<SysFSRootDirectory> m_root_directory;
- Spinlock m_root_directory_lock { LockRank::None };
+ Spinlock<LockRank::None> m_root_directory_lock {};
};
}
diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h
index 9a72bc0bee..36761345b9 100644
--- a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h
+++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h
@@ -27,7 +27,7 @@ public:
private:
explicit SysFSUSBBusDirectory(SysFSBusDirectory&);
- mutable Spinlock m_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_lock {};
};
}
diff --git a/Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/CapsLockRemap.h b/Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/CapsLockRemap.h
index f0bd11bf9f..a4b18c8f49 100644
--- a/Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/CapsLockRemap.h
+++ b/Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/CapsLockRemap.h
@@ -25,7 +25,7 @@ private:
explicit SysFSCapsLockRemap(SysFSDirectory const&);
- mutable Spinlock m_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_lock {};
};
}
diff --git a/Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/DumpKmallocStack.h b/Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/DumpKmallocStack.h
index 1bc2ad995e..8b8ab77f0d 100644
--- a/Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/DumpKmallocStack.h
+++ b/Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/DumpKmallocStack.h
@@ -25,7 +25,7 @@ private:
explicit SysFSDumpKmallocStacks(SysFSDirectory const&);
- mutable Spinlock m_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_lock {};
};
}
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp
index 98621c85ec..fb45580216 100644
--- a/Kernel/FileSystem/VirtualFileSystem.cpp
+++ b/Kernel/FileSystem/VirtualFileSystem.cpp
@@ -39,7 +39,6 @@ VirtualFileSystem& VirtualFileSystem::the()
}
UNMAP_AFTER_INIT VirtualFileSystem::VirtualFileSystem()
- : m_root_custody(LockRank::None)
{
}
diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h
index 07c5af9055..06a8b7abc8 100644
--- a/Kernel/FileSystem/VirtualFileSystem.h
+++ b/Kernel/FileSystem/VirtualFileSystem.h
@@ -113,11 +113,11 @@ private:
LockRefPtr<Inode> m_root_inode;
- SpinlockProtected<RefPtr<Custody>> m_root_custody;
+ SpinlockProtected<RefPtr<Custody>, LockRank::None> m_root_custody {};
- SpinlockProtected<IntrusiveList<&Mount::m_vfs_list_node>> m_mounts { LockRank::None };
- SpinlockProtected<IntrusiveList<&FileBackedFileSystem::m_file_backed_file_system_node>> m_file_backed_file_systems_list { LockRank::None };
- SpinlockProtected<IntrusiveList<&FileSystem::m_file_system_node>> m_file_systems_list { LockRank::FileSystem };
+ SpinlockProtected<IntrusiveList<&Mount::m_vfs_list_node>, LockRank::None> m_mounts {};
+ SpinlockProtected<IntrusiveList<&FileBackedFileSystem::m_file_backed_file_system_node>, LockRank::None> m_file_backed_file_systems_list {};
+ SpinlockProtected<IntrusiveList<&FileSystem::m_file_system_node>, LockRank::FileSystem> m_file_systems_list {};
};
}
diff --git a/Kernel/Forward.h b/Kernel/Forward.h
index 279abeae1d..88f53b2fda 100644
--- a/Kernel/Forward.h
+++ b/Kernel/Forward.h
@@ -11,6 +11,8 @@
namespace Kernel {
+enum class LockRank;
+
class BlockDevice;
class CharacterDevice;
class Coredump;
@@ -48,6 +50,7 @@ class ProcFSSystemBoolean;
class ProcFSSystemDirectory;
class Process;
class ProcessGroup;
+template<LockRank Rank>
class RecursiveSpinlock;
class Scheduler;
class Socket;
@@ -85,6 +88,7 @@ class VMObject;
class VirtualRange;
}
+template<LockRank Rank>
class Spinlock;
template<typename LockType>
class SpinlockLocker;
diff --git a/Kernel/Graphics/Console/BootFramebufferConsole.h b/Kernel/Graphics/Console/BootFramebufferConsole.h
index b9819f5e12..1236656b50 100644
--- a/Kernel/Graphics/Console/BootFramebufferConsole.h
+++ b/Kernel/Graphics/Console/BootFramebufferConsole.h
@@ -39,7 +39,7 @@ protected:
OwnPtr<Memory::Region> m_framebuffer;
u8* m_framebuffer_data {};
- mutable Spinlock m_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_lock {};
};
}
diff --git a/Kernel/Graphics/Console/GenericFramebufferConsole.h b/Kernel/Graphics/Console/GenericFramebufferConsole.h
index 0b38e43097..88ace335bd 100644
--- a/Kernel/Graphics/Console/GenericFramebufferConsole.h
+++ b/Kernel/Graphics/Console/GenericFramebufferConsole.h
@@ -81,7 +81,7 @@ protected:
virtual void clear_glyph(size_t x, size_t y) override;
- mutable Spinlock m_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_lock {};
};
}
diff --git a/Kernel/Graphics/Console/VGATextModeConsole.h b/Kernel/Graphics/Console/VGATextModeConsole.h
index e67125b2dc..f487b1bfae 100644
--- a/Kernel/Graphics/Console/VGATextModeConsole.h
+++ b/Kernel/Graphics/Console/VGATextModeConsole.h
@@ -38,7 +38,7 @@ private:
explicit VGATextModeConsole(NonnullOwnPtr<Memory::Region>);
- mutable Spinlock m_vga_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_vga_lock {};
NonnullOwnPtr<Memory::Region> m_vga_window_region;
VirtualAddress m_current_vga_window;
diff --git a/Kernel/Graphics/DisplayConnector.h b/Kernel/Graphics/DisplayConnector.h
index fd7e883070..157dffcbb0 100644
--- a/Kernel/Graphics/DisplayConnector.h
+++ b/Kernel/Graphics/DisplayConnector.h
@@ -114,14 +114,14 @@ protected:
ErrorOr<void> initialize_edid_for_generic_monitor(Optional<Array<u8, 3>> manufacturer_id_string);
- mutable Spinlock m_control_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_control_lock {};
mutable Mutex m_flushing_lock;
bool m_console_mode { false };
bool m_vertical_offsetted { false };
- mutable Spinlock m_modeset_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_modeset_lock {};
ModeSetting m_current_mode_setting {};
Optional<EDID::Parser> m_edid_parser;
@@ -165,7 +165,7 @@ private:
LockRefPtr<Memory::SharedFramebufferVMObject> m_shared_framebuffer_vmobject;
LockWeakPtr<Process> m_responsible_process;
- Spinlock m_responsible_process_lock { LockRank::None };
+ Spinlock<LockRank::None> m_responsible_process_lock {};
IntrusiveListNode<DisplayConnector, LockRefPtr<DisplayConnector>> m_list_node;
};
diff --git a/Kernel/Graphics/GraphicsManagement.h b/Kernel/Graphics/GraphicsManagement.h
index 17e17bd06b..ec771c6528 100644
--- a/Kernel/Graphics/GraphicsManagement.h
+++ b/Kernel/Graphics/GraphicsManagement.h
@@ -64,7 +64,7 @@ private:
unsigned m_current_minor_number { 0 };
- SpinlockProtected<IntrusiveList<&DisplayConnector::m_list_node>> m_display_connector_nodes { LockRank::None };
+ SpinlockProtected<IntrusiveList<&DisplayConnector::m_list_node>, LockRank::None> m_display_connector_nodes {};
#if ARCH(X86_64)
OwnPtr<VGAIOArbiter> m_vga_arbiter;
#endif
diff --git a/Kernel/Graphics/Intel/NativeDisplayConnector.h b/Kernel/Graphics/Intel/NativeDisplayConnector.h
index a5d77a20b1..0cd60a4358 100644
--- a/Kernel/Graphics/Intel/NativeDisplayConnector.h
+++ b/Kernel/Graphics/Intel/NativeDisplayConnector.h
@@ -154,7 +154,7 @@ private:
Optional<IntelGraphics::PLLSettings> create_pll_settings(u64 target_frequency, u64 reference_clock, IntelGraphics::PLLMaxSettings const&);
- mutable Spinlock m_registers_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_registers_lock {};
LockRefPtr<Graphics::GenericFramebufferConsole> m_framebuffer_console;
const PhysicalAddress m_registers;
diff --git a/Kernel/Graphics/VMWare/GraphicsAdapter.h b/Kernel/Graphics/VMWare/GraphicsAdapter.h
index 9f414dadb8..705b60865e 100644
--- a/Kernel/Graphics/VMWare/GraphicsAdapter.h
+++ b/Kernel/Graphics/VMWare/GraphicsAdapter.h
@@ -51,8 +51,8 @@ private:
Memory::TypedMapping<VMWareDisplayFIFORegisters volatile> m_fifo_registers;
LockRefPtr<VMWareDisplayConnector> m_display_connector;
mutable NonnullOwnPtr<IOWindow> m_registers_io_window;
- mutable Spinlock m_io_access_lock { LockRank::None };
- mutable RecursiveSpinlock m_operation_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_io_access_lock {};
+ mutable RecursiveSpinlock<LockRank::None> m_operation_lock {};
};
}
diff --git a/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h
index 2b5bedccb6..5b93a51820 100644
--- a/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h
+++ b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h
@@ -112,11 +112,11 @@ private:
VirtIO::Configuration const* m_device_configuration { nullptr };
// Note: Resource ID 0 is invalid, and we must not allocate 0 as the first resource ID.
Atomic<u32> m_resource_id_counter { 1 };
- SpinlockProtected<Bitmap> m_active_context_ids { LockRank::None };
+ SpinlockProtected<Bitmap, LockRank::None> m_active_context_ids {};
LockRefPtr<VirtIOGPU3DDevice> m_3d_device;
bool m_has_virgl_support { false };
- Spinlock m_operation_lock { LockRank::None };
+ Spinlock<LockRank::None> m_operation_lock {};
NonnullOwnPtr<Memory::Region> m_scratch_space;
};
}
diff --git a/Kernel/Heap/kmalloc.cpp b/Kernel/Heap/kmalloc.cpp
index de4a192399..6330550570 100644
--- a/Kernel/Heap/kmalloc.cpp
+++ b/Kernel/Heap/kmalloc.cpp
@@ -36,7 +36,7 @@ const nothrow_t nothrow;
}
// FIXME: Figure out whether this can be MemoryManager.
-static RecursiveSpinlock s_lock { LockRank::None }; // needs to be recursive because of dump_backtrace()
+static RecursiveSpinlock<LockRank::None> s_lock {}; // needs to be recursive because of dump_backtrace()
struct KmallocSubheap {
KmallocSubheap(u8* base, size_t size)
diff --git a/Kernel/Jail.h b/Kernel/Jail.h
index 8dc623193a..bfbc6c833a 100644
--- a/Kernel/Jail.h
+++ b/Kernel/Jail.h
@@ -34,7 +34,7 @@ public:
JailIndex index() const { return m_index; }
void detach(Badge<Process>);
- SpinlockProtected<size_t>& attach_count() { return m_attach_count; }
+ SpinlockProtected<size_t, LockRank::None>& attach_count() { return m_attach_count; }
private:
Jail(NonnullOwnPtr<KString>, JailIndex);
@@ -43,7 +43,7 @@ private:
JailIndex const m_index;
IntrusiveListNode<Jail, NonnullLockRefPtr<Jail>> m_jail_list_node;
- SpinlockProtected<size_t> m_attach_count { LockRank::None, 0 };
+ SpinlockProtected<size_t, LockRank::None> m_attach_count { 0 };
};
}
diff --git a/Kernel/JailManagement.h b/Kernel/JailManagement.h
index 9f363bed66..76fe91cf82 100644
--- a/Kernel/JailManagement.h
+++ b/Kernel/JailManagement.h
@@ -36,7 +36,7 @@ public:
private:
JailIndex generate_jail_id();
- SpinlockProtected<IntrusiveList<&Jail::m_jail_list_node>> m_jails { LockRank::None };
+ SpinlockProtected<IntrusiveList<&Jail::m_jail_list_node>, LockRank::None> m_jails {};
};
}
diff --git a/Kernel/Locking/Mutex.cpp b/Kernel/Locking/Mutex.cpp
index 99f836a077..5e4606add4 100644
--- a/Kernel/Locking/Mutex.cpp
+++ b/Kernel/Locking/Mutex.cpp
@@ -211,7 +211,7 @@ void Mutex::unlock()
}
}
-void Mutex::block(Thread& current_thread, Mode mode, SpinlockLocker<Spinlock>& lock, u32 requested_locks)
+void Mutex::block(Thread& current_thread, Mode mode, SpinlockLocker<Spinlock<LockRank::None>>& lock, u32 requested_locks)
{
if constexpr (LOCK_IN_CRITICAL_DEBUG) {
// There are no interrupts enabled in early boot.
diff --git a/Kernel/Locking/Mutex.h b/Kernel/Locking/Mutex.h
index beba56f8a0..17d59925ec 100644
--- a/Kernel/Locking/Mutex.h
+++ b/Kernel/Locking/Mutex.h
@@ -82,7 +82,8 @@ private:
// FIXME: remove this after annihilating Process::m_big_lock
using BigLockBlockedThreadList = IntrusiveList<&Thread::m_big_lock_blocked_threads_list_node>;
- void block(Thread&, Mode, SpinlockLocker<Spinlock>&, u32);
+ // FIXME: Allow any lock rank.
+ void block(Thread&, Mode, SpinlockLocker<Spinlock<LockRank::None>>&, u32);
void unblock_waiters(Mode);
StringView m_name;
@@ -117,10 +118,10 @@ private:
}
};
// FIXME: Use a specific lock rank passed by constructor.
- SpinlockProtected<BlockedThreadLists> m_blocked_thread_lists { LockRank::None };
+ SpinlockProtected<BlockedThreadLists, LockRank::None> m_blocked_thread_lists {};
// FIXME: See above.
- mutable Spinlock m_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_lock {};
#if LOCK_SHARED_UPGRADE_DEBUG
HashMap<Thread*, u32> m_shared_holders_map;
diff --git a/Kernel/Locking/Spinlock.cpp b/Kernel/Locking/Spinlock.cpp
deleted file mode 100644
index 7c1f57a2a1..0000000000
--- a/Kernel/Locking/Spinlock.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <Kernel/Locking/Spinlock.h>
-
-namespace Kernel {
-
-InterruptsState Spinlock::lock()
-{
- InterruptsState previous_interrupts_state = processor_interrupts_state();
- Processor::enter_critical();
- Processor::disable_interrupts();
- while (m_lock.exchange(1, AK::memory_order_acquire) != 0)
- Processor::wait_check();
- track_lock_acquire(m_rank);
- return previous_interrupts_state;
-}
-
-void Spinlock::unlock(InterruptsState previous_interrupts_state)
-{
- VERIFY(is_locked());
- track_lock_release(m_rank);
- m_lock.store(0, AK::memory_order_release);
-
- Processor::leave_critical();
- restore_processor_interrupts_state(previous_interrupts_state);
-}
-
-InterruptsState RecursiveSpinlock::lock()
-{
- InterruptsState previous_interrupts_state = processor_interrupts_state();
- Processor::disable_interrupts();
- Processor::enter_critical();
- auto& proc = Processor::current();
- FlatPtr cpu = FlatPtr(&proc);
- FlatPtr expected = 0;
- while (!m_lock.compare_exchange_strong(expected, cpu, AK::memory_order_acq_rel)) {
- if (expected == cpu)
- break;
- Processor::wait_check();
- expected = 0;
- }
- if (m_recursions == 0)
- track_lock_acquire(m_rank);
- m_recursions++;
- return previous_interrupts_state;
-}
-
-void RecursiveSpinlock::unlock(InterruptsState previous_interrupts_state)
-{
- VERIFY_INTERRUPTS_DISABLED();
- VERIFY(m_recursions > 0);
- VERIFY(m_lock.load(AK::memory_order_relaxed) == FlatPtr(&Processor::current()));
- if (--m_recursions == 0) {
- track_lock_release(m_rank);
- m_lock.store(0, AK::memory_order_release);
- }
-
- Processor::leave_critical();
- restore_processor_interrupts_state(previous_interrupts_state);
-}
-
-}
diff --git a/Kernel/Locking/Spinlock.h b/Kernel/Locking/Spinlock.h
index a7177d4209..fea5836b9e 100644
--- a/Kernel/Locking/Spinlock.h
+++ b/Kernel/Locking/Spinlock.h
@@ -13,18 +13,34 @@
namespace Kernel {
+template<LockRank Rank>
class Spinlock {
AK_MAKE_NONCOPYABLE(Spinlock);
AK_MAKE_NONMOVABLE(Spinlock);
public:
- Spinlock(LockRank rank)
- : m_rank(rank)
+ Spinlock() = default;
+
+ InterruptsState lock()
{
+ InterruptsState previous_interrupts_state = processor_interrupts_state();
+ Processor::enter_critical();
+ Processor::disable_interrupts();
+ while (m_lock.exchange(1, AK::memory_order_acquire) != 0)
+ Processor::wait_check();
+ track_lock_acquire(m_rank);
+ return previous_interrupts_state;
}
- InterruptsState lock();
- void unlock(InterruptsState);
+ void unlock(InterruptsState previous_interrupts_state)
+ {
+ VERIFY(is_locked());
+ track_lock_release(m_rank);
+ m_lock.store(0, AK::memory_order_release);
+
+ Processor::leave_critical();
+ restore_processor_interrupts_state(previous_interrupts_state);
+ }
[[nodiscard]] ALWAYS_INLINE bool is_locked() const
{
@@ -38,21 +54,50 @@ public:
private:
Atomic<u8> m_lock { 0 };
- const LockRank m_rank;
+ static constexpr LockRank const m_rank { Rank };
};
+template<LockRank Rank>
class RecursiveSpinlock {
AK_MAKE_NONCOPYABLE(RecursiveSpinlock);
AK_MAKE_NONMOVABLE(RecursiveSpinlock);
public:
- RecursiveSpinlock(LockRank rank)
- : m_rank(rank)
+ RecursiveSpinlock() = default;
+
+ InterruptsState lock()
{
+ InterruptsState previous_interrupts_state = processor_interrupts_state();
+ Processor::disable_interrupts();
+ Processor::enter_critical();
+ auto& proc = Processor::current();
+ FlatPtr cpu = FlatPtr(&proc);
+ FlatPtr expected = 0;
+ while (!m_lock.compare_exchange_strong(expected, cpu, AK::memory_order_acq_rel)) {
+ if (expected == cpu)
+ break;
+ Processor::wait_check();
+ expected = 0;
+ }
+ if (m_recursions == 0)
+ track_lock_acquire(m_rank);
+ m_recursions++;
+ return previous_interrupts_state;
}
- InterruptsState lock();
- void unlock(InterruptsState);
+ void unlock(InterruptsState previous_interrupts_state)
+ {
+ VERIFY_INTERRUPTS_DISABLED();
+ VERIFY(m_recursions > 0);
+ VERIFY(m_lock.load(AK::memory_order_relaxed) == FlatPtr(&Processor::current()));
+ if (--m_recursions == 0) {
+ track_lock_release(m_rank);
+ m_lock.store(0, AK::memory_order_release);
+ }
+
+ Processor::leave_critical();
+ restore_processor_interrupts_state(previous_interrupts_state);
+ }
[[nodiscard]] ALWAYS_INLINE bool is_locked() const
{
@@ -72,7 +117,7 @@ public:
private:
Atomic<FlatPtr> m_lock { 0 };
u32 m_recursions { 0 };
- const LockRank m_rank;
+ static constexpr LockRank const m_rank { Rank };
};
template<typename LockType>
diff --git a/Kernel/Locking/SpinlockProtected.h b/Kernel/Locking/SpinlockProtected.h
index e40248b7fd..ced5e941cb 100644
--- a/Kernel/Locking/SpinlockProtected.h
+++ b/Kernel/Locking/SpinlockProtected.h
@@ -10,7 +10,7 @@
namespace Kernel {
-template<typename T>
+template<typename T, LockRank Rank>
class SpinlockProtected {
AK_MAKE_NONCOPYABLE(SpinlockProtected);
AK_MAKE_NONMOVABLE(SpinlockProtected);
@@ -22,7 +22,7 @@ private:
AK_MAKE_NONMOVABLE(Locked);
public:
- Locked(U& value, RecursiveSpinlock& spinlock)
+ Locked(U& value, RecursiveSpinlock<Rank>& spinlock)
: m_value(value)
, m_locker(spinlock)
{
@@ -39,7 +39,7 @@ private:
private:
U& m_value;
- SpinlockLocker<RecursiveSpinlock> m_locker;
+ SpinlockLocker<RecursiveSpinlock<Rank>> m_locker;
};
auto lock_const() const { return Locked<T const>(m_value, m_spinlock); }
@@ -47,9 +47,8 @@ private:
public:
template<typename... Args>
- SpinlockProtected(LockRank rank, Args&&... args)
+ SpinlockProtected(Args&&... args)
: m_value(forward<Args>(args)...)
- , m_spinlock(rank)
{
}
@@ -87,7 +86,8 @@ public:
private:
T m_value;
- RecursiveSpinlock mutable m_spinlock;
+ RecursiveSpinlock<Rank> mutable m_spinlock;
+ static constexpr LockRank const m_rank { Rank };
};
}
diff --git a/Kernel/Memory/AnonymousVMObject.h b/Kernel/Memory/AnonymousVMObject.h
index d880dd8b87..6bee370e4c 100644
--- a/Kernel/Memory/AnonymousVMObject.h
+++ b/Kernel/Memory/AnonymousVMObject.h
@@ -78,7 +78,7 @@ private:
void uncommit_one();
private:
- Spinlock m_lock { LockRank::None };
+ Spinlock<LockRank::None> m_lock {};
CommittedPhysicalPageSet m_committed_pages;
};
diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp
index 5e80e9cbc1..a0d4af14c1 100644
--- a/Kernel/Memory/MemoryManager.cpp
+++ b/Kernel/Memory/MemoryManager.cpp
@@ -88,7 +88,6 @@ MemoryManager::GlobalData::GlobalData()
}
UNMAP_AFTER_INIT MemoryManager::MemoryManager()
- : m_global_data(LockRank::None)
{
s_the = this;
diff --git a/Kernel/Memory/MemoryManager.h b/Kernel/Memory/MemoryManager.h
index 484a645acc..e4b0b57954 100644
--- a/Kernel/Memory/MemoryManager.h
+++ b/Kernel/Memory/MemoryManager.h
@@ -89,7 +89,7 @@ struct PhysicalMemoryRange {
struct MemoryManagerData {
static ProcessorSpecificDataID processor_specific_data_id() { return ProcessorSpecificDataID::MemoryManager; }
- Spinlock m_quickmap_in_use { LockRank::None };
+ Spinlock<LockRank::None> m_quickmap_in_use {};
InterruptsState m_quickmap_previous_interrupts_state;
};
@@ -304,7 +304,7 @@ private:
Vector<ContiguousReservedMemoryRange> reserved_memory_ranges;
};
- SpinlockProtected<GlobalData> m_global_data;
+ SpinlockProtected<GlobalData, LockRank::None> m_global_data;
};
inline bool is_user_address(VirtualAddress vaddr)
diff --git a/Kernel/Memory/PageDirectory.h b/Kernel/Memory/PageDirectory.h
index e5e3f8d043..5ae014464c 100644
--- a/Kernel/Memory/PageDirectory.h
+++ b/Kernel/Memory/PageDirectory.h
@@ -52,7 +52,7 @@ public:
void set_space(Badge<AddressSpace>, AddressSpace& space) { m_space = &space; }
- RecursiveSpinlock& get_lock() { return m_lock; }
+ RecursiveSpinlock<LockRank::None>& get_lock() { return m_lock; }
// This has to be public to let the global singleton access the member pointer
IntrusiveRedBlackTreeNode<FlatPtr, PageDirectory, RawPtr<PageDirectory>> m_tree_node;
@@ -72,7 +72,7 @@ private:
#else
RefPtr<PhysicalPage> m_directory_pages[4];
#endif
- RecursiveSpinlock m_lock { LockRank::None };
+ RecursiveSpinlock<LockRank::None> m_lock {};
};
void activate_kernel_page_directory(PageDirectory const& pgd);
diff --git a/Kernel/Memory/Region.cpp b/Kernel/Memory/Region.cpp
index 4dd3e6c102..2c4d0f7ed2 100644
--- a/Kernel/Memory/Region.cpp
+++ b/Kernel/Memory/Region.cpp
@@ -270,7 +270,7 @@ void Region::unmap(ShouldFlushTLB should_flush_tlb)
unmap_with_locks_held(should_flush_tlb, pd_locker);
}
-void Region::unmap_with_locks_held(ShouldFlushTLB should_flush_tlb, SpinlockLocker<RecursiveSpinlock>&)
+void Region::unmap_with_locks_held(ShouldFlushTLB should_flush_tlb, SpinlockLocker<RecursiveSpinlock<LockRank::None>>&)
{
if (!m_page_directory)
return;
diff --git a/Kernel/Memory/Region.h b/Kernel/Memory/Region.h
index bc435e3841..3955c01bca 100644
--- a/Kernel/Memory/Region.h
+++ b/Kernel/Memory/Region.h
@@ -13,6 +13,7 @@
#include <Kernel/Forward.h>
#include <Kernel/KString.h>
#include <Kernel/Library/LockWeakable.h>
+#include <Kernel/Locking/LockRank.h>
#include <Kernel/Memory/PageFaultResponse.h>
#include <Kernel/Memory/VirtualRange.h>
#include <Kernel/Sections.h>
@@ -192,7 +193,7 @@ public:
void set_page_directory(PageDirectory&);
ErrorOr<void> map(PageDirectory&, ShouldFlushTLB = ShouldFlushTLB::Yes);
void unmap(ShouldFlushTLB = ShouldFlushTLB::Yes);
- void unmap_with_locks_held(ShouldFlushTLB, SpinlockLocker<RecursiveSpinlock>& pd_locker);
+ void unmap_with_locks_held(ShouldFlushTLB, SpinlockLocker<RecursiveSpinlock<LockRank::None>>& pd_locker);
void remap();
diff --git a/Kernel/Memory/RingBuffer.h b/Kernel/Memory/RingBuffer.h
index 2ea0811e3a..74ff355b29 100644
--- a/Kernel/Memory/RingBuffer.h
+++ b/Kernel/Memory/RingBuffer.h
@@ -22,7 +22,7 @@ public:
void reclaim_space(PhysicalAddress chunk_start, size_t chunk_size);
PhysicalAddress start_of_used() const;
- Spinlock& lock() { return m_lock; }
+ Spinlock<LockRank::None>& lock() { return m_lock; }
size_t used_bytes() const { return m_num_used_bytes; }
PhysicalAddress start_of_region() const { return m_region->physical_page(0)->paddr(); }
VirtualAddress vaddr() const { return m_region->vaddr(); }
@@ -32,7 +32,7 @@ private:
RingBuffer(NonnullOwnPtr<Memory::Region> region, size_t capacity);
NonnullOwnPtr<Memory::Region> m_region;
- Spinlock m_lock { LockRank::None };
+ Spinlock<LockRank::None> m_lock {};
size_t m_start_of_used {};
size_t m_num_used_bytes {};
size_t m_capacity_in_bytes {};
diff --git a/Kernel/Memory/SharedFramebufferVMObject.h b/Kernel/Memory/SharedFramebufferVMObject.h
index 2c95d4eb6d..a43144c19a 100644
--- a/Kernel/Memory/SharedFramebufferVMObject.h
+++ b/Kernel/Memory/SharedFramebufferVMObject.h
@@ -87,7 +87,7 @@ private:
LockRefPtr<FakeWritesFramebufferVMObject> m_fake_writes_framebuffer_vmobject;
LockRefPtr<RealWritesFramebufferVMObject> m_real_writes_framebuffer_vmobject;
bool m_writes_are_faked { false };
- mutable RecursiveSpinlock m_writes_state_lock { LockRank::None };
+ mutable RecursiveSpinlock<LockRank::None> m_writes_state_lock {};
CommittedPhysicalPageSet m_committed_pages;
};
diff --git a/Kernel/Memory/VMObject.cpp b/Kernel/Memory/VMObject.cpp
index d6d09c888b..3d241a6606 100644
--- a/Kernel/Memory/VMObject.cpp
+++ b/Kernel/Memory/VMObject.cpp
@@ -10,9 +10,9 @@
namespace Kernel::Memory {
-static Singleton<SpinlockProtected<VMObject::AllInstancesList>> s_all_instances;
+static Singleton<SpinlockProtected<VMObject::AllInstancesList, LockRank::None>> s_all_instances;
-SpinlockProtected<VMObject::AllInstancesList>& VMObject::all_instances()
+SpinlockProtected<VMObject::AllInstancesList, LockRank::None>& VMObject::all_instances()
{
return s_all_instances;
}
diff --git a/Kernel/Memory/VMObject.h b/Kernel/Memory/VMObject.h
index d6cc4ecce4..8dcdf7e098 100644
--- a/Kernel/Memory/VMObject.h
+++ b/Kernel/Memory/VMObject.h
@@ -65,7 +65,7 @@ protected:
IntrusiveListNode<VMObject> m_list_node;
FixedArray<RefPtr<PhysicalPage>> m_physical_pages;
- mutable RecursiveSpinlock m_lock { LockRank::None };
+ mutable RecursiveSpinlock<LockRank::None> m_lock {};
private:
VMObject& operator=(VMObject const&) = delete;
@@ -76,7 +76,7 @@ private:
public:
using AllInstancesList = IntrusiveList<&VMObject::m_list_node>;
- static SpinlockProtected<VMObject::AllInstancesList>& all_instances();
+ static SpinlockProtected<VMObject::AllInstancesList, LockRank::None>& all_instances();
};
template<typename Callback>
diff --git a/Kernel/Net/NetworkAdapter.h b/Kernel/Net/NetworkAdapter.h
index 0b0ac82a63..6e8bdd1782 100644
--- a/Kernel/Net/NetworkAdapter.h
+++ b/Kernel/Net/NetworkAdapter.h
@@ -111,7 +111,7 @@ private:
PacketList m_packet_queue;
size_t m_packet_queue_size { 0 };
- SpinlockProtected<PacketList> m_unused_packets { LockRank::None };
+ SpinlockProtected<PacketList, LockRank::None> m_unused_packets {};
NonnullOwnPtr<KString> m_name;
u32 m_packets_in { 0 };
u32 m_bytes_in { 0 };
diff --git a/Kernel/Net/NetworkingManagement.h b/Kernel/Net/NetworkingManagement.h
index 8b8955e919..ab4f3bc25f 100644
--- a/Kernel/Net/NetworkingManagement.h
+++ b/Kernel/Net/NetworkingManagement.h
@@ -42,7 +42,7 @@ public:
private:
ErrorOr<NonnullLockRefPtr<NetworkAdapter>> determine_network_device(PCI::DeviceIdentifier const&) const;
- SpinlockProtected<NonnullLockRefPtrVector<NetworkAdapter>> m_adapters { LockRank::None };
+ SpinlockProtected<NonnullLockRefPtrVector<NetworkAdapter>, LockRank::None> m_adapters {};
LockRefPtr<NetworkAdapter> m_loopback_adapter;
};
diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp
index 5711cd1359..81ca0b000c 100644
--- a/Kernel/Net/Routing.cpp
+++ b/Kernel/Net/Routing.cpp
@@ -16,8 +16,8 @@
namespace Kernel {
-static Singleton<SpinlockProtected<HashMap<IPv4Address, MACAddress>>> s_arp_table;
-static Singleton<SpinlockProtected<Route::RouteList>> s_routing_table;
+static Singleton<SpinlockProtected<HashMap<IPv4Address, MACAddress>, LockRank::None>> s_arp_table;
+static Singleton<SpinlockProtected<Route::RouteList, LockRank::None>> s_routing_table;
class ARPTableBlocker final : public Thread::Blocker {
public:
@@ -106,7 +106,7 @@ void ARPTableBlocker::will_unblock_immediately_without_blocking(UnblockImmediate
}
}
-SpinlockProtected<HashMap<IPv4Address, MACAddress>>& arp_table()
+SpinlockProtected<HashMap<IPv4Address, MACAddress>, LockRank::None>& arp_table()
{
return *s_arp_table;
}
@@ -130,7 +130,7 @@ void update_arp_table(IPv4Address const& ip_addr, MACAddress const& addr, Update
}
}
-SpinlockProtected<Route::RouteList>& routing_table()
+SpinlockProtected<Route::RouteList, LockRank::None>& routing_table()
{
return *s_routing_table;
}
diff --git a/Kernel/Net/Routing.h b/Kernel/Net/Routing.h
index b1cd26b4d6..8732184901 100644
--- a/Kernel/Net/Routing.h
+++ b/Kernel/Net/Routing.h
@@ -66,7 +66,7 @@ enum class AllowUsingGateway {
RoutingDecision route_to(IPv4Address const& target, IPv4Address const& source, LockRefPtr<NetworkAdapter> const through = nullptr, AllowUsingGateway = AllowUsingGateway::Yes);
-SpinlockProtected<HashMap<IPv4Address, MACAddress>>& arp_table();
-SpinlockProtected<Route::RouteList>& routing_table();
+SpinlockProtected<HashMap<IPv4Address, MACAddress>, LockRank::None>& arp_table();
+SpinlockProtected<Route::RouteList, LockRank::None>& routing_table();
}
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 51bb92217d..d2fbf3f3f3 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -46,9 +46,9 @@ static void create_signal_trampoline();
extern ProcessID g_init_pid;
-RecursiveSpinlock g_profiling_lock { LockRank::None };
+RecursiveSpinlock<LockRank::None> g_profiling_lock {};
static Atomic<pid_t> next_pid;
-static Singleton<SpinlockProtected<Process::List>> s_all_instances;
+static Singleton<SpinlockProtected<Process::List, LockRank::None>> s_all_instances;
READONLY_AFTER_INIT Memory::Region* g_signal_trampoline_region;
static Singleton<MutexProtected<OwnPtr<KString>>> s_hostname;
@@ -58,7 +58,7 @@ MutexProtected<OwnPtr<KString>>& hostname()
return *s_hostname;
}
-SpinlockProtected<Process::List>& Process::all_instances()
+SpinlockProtected<Process::List, LockRank::None>& Process::all_instances()
{
return *s_all_instances;
}
@@ -319,14 +319,12 @@ ErrorOr<NonnullLockRefPtr<Process>> Process::try_create(LockRefPtr<Thread>& firs
Process::Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials> credentials, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory, RefPtr<Custody> executable, TTY* tty, UnveilNode unveil_tree, UnveilNode exec_unveil_tree)
: m_name(move(name))
- , m_space(LockRank::None)
- , m_protected_data_lock(LockRank::None)
, m_is_kernel_process(is_kernel_process)
- , m_executable(LockRank::None, move(executable))
- , m_current_directory(LockRank::None, move(current_directory))
+ , m_executable(move(executable))
+ , m_current_directory(move(current_directory))
, m_tty(tty)
- , m_unveil_data(LockRank::None, move(unveil_tree))
- , m_exec_unveil_data(LockRank::None, move(exec_unveil_tree))
+ , m_unveil_data(move(unveil_tree))
+ , m_exec_unveil_data(move(exec_unveil_tree))
, m_wait_blocker_set(*this)
{
// Ensure that we protect the process data when exiting the constructor.
diff --git a/Kernel/Process.h b/Kernel/Process.h
index c897d4f962..c7613f3e1c 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -238,7 +238,7 @@ public:
return with_protected_data([](auto& protected_data) { return protected_data.ppid; });
}
- SpinlockProtected<RefPtr<Jail>>& jail() { return m_attached_jail; }
+ SpinlockProtected<RefPtr<Jail>, LockRank::Process>& jail() { return m_attached_jail; }
NonnullRefPtr<Credentials> credentials() const;
@@ -568,8 +568,8 @@ public:
PerformanceEventBuffer* perf_events() { return m_perf_event_buffer; }
PerformanceEventBuffer const* perf_events() const { return m_perf_event_buffer; }
- SpinlockProtected<OwnPtr<Memory::AddressSpace>>& address_space() { return m_space; }
- SpinlockProtected<OwnPtr<Memory::AddressSpace>> const& address_space() const { return m_space; }
+ SpinlockProtected<OwnPtr<Memory::AddressSpace>, LockRank::None>& address_space() { return m_space; }
+ SpinlockProtected<OwnPtr<Memory::AddressSpace>, LockRank::None> const& address_space() const { return m_space; }
VirtualAddress signal_trampoline() const
{
@@ -666,11 +666,11 @@ private:
NonnullOwnPtr<KString> m_name;
- SpinlockProtected<OwnPtr<Memory::AddressSpace>> m_space;
+ SpinlockProtected<OwnPtr<Memory::AddressSpace>, LockRank::None> m_space;
LockRefPtr<ProcessGroup> m_pg;
- RecursiveSpinlock mutable m_protected_data_lock;
+ RecursiveSpinlock<LockRank::None> mutable m_protected_data_lock;
AtomicEdgeAction<u32> m_protected_data_refs;
void protect_data();
void unprotect_data();
@@ -849,12 +849,12 @@ public:
private:
ErrorOr<NonnullRefPtr<Custody>> custody_for_dirfd(int dirfd);
- SpinlockProtected<Thread::ListInProcess>& thread_list() { return m_thread_list; }
- SpinlockProtected<Thread::ListInProcess> const& thread_list() const { return m_thread_list; }
+ SpinlockProtected<Thread::ListInProcess, LockRank::None>& thread_list() { return m_thread_list; }
+ SpinlockProtected<Thread::ListInProcess, LockRank::None> const& thread_list() const { return m_thread_list; }
ErrorOr<NonnullRefPtr<Thread>> get_thread_from_pid_or_tid(pid_t pid_or_tid, Syscall::SchedulerParametersMode mode);
- SpinlockProtected<Thread::ListInProcess> m_thread_list { LockRank::None };
+ SpinlockProtected<Thread::ListInProcess, LockRank::None> m_thread_list {};
MutexProtected<OpenFileDescriptions> m_fds;
@@ -864,9 +864,9 @@ private:
Atomic<bool, AK::MemoryOrder::memory_order_relaxed> m_is_stopped { false };
bool m_should_generate_coredump { false };
- SpinlockProtected<RefPtr<Custody>> m_executable;
+ SpinlockProtected<RefPtr<Custody>, LockRank::None> m_executable;
- SpinlockProtected<RefPtr<Custody>> m_current_directory;
+ SpinlockProtected<RefPtr<Custody>, LockRank::None> m_current_directory;
NonnullOwnPtrVector<KString> m_arguments;
NonnullOwnPtrVector<KString> m_environment;
@@ -876,7 +876,7 @@ private:
LockWeakPtr<Memory::Region> m_master_tls_region;
IntrusiveListNode<Process> m_jail_list_node;
- SpinlockProtected<RefPtr<Jail>> m_attached_jail { LockRank::Process };
+ SpinlockProtected<RefPtr<Jail>, LockRank::Process> m_attached_jail {};
size_t m_master_tls_size { 0 };
size_t m_master_tls_alignment { 0 };
@@ -886,8 +886,8 @@ private:
LockRefPtr<Timer> m_alarm_timer;
- SpinlockProtected<UnveilData> m_unveil_data;
- SpinlockProtected<UnveilData> m_exec_unveil_data;
+ SpinlockProtected<UnveilData, LockRank::None> m_unveil_data;
+ SpinlockProtected<UnveilData, LockRank::None> m_exec_unveil_data;
OwnPtr<PerformanceEventBuffer> m_perf_event_buffer;
@@ -903,7 +903,7 @@ private:
OwnPtr<KString> value;
};
- SpinlockProtected<Array<CoredumpProperty, 4>> m_coredump_properties { LockRank::None };
+ SpinlockProtected<Array<CoredumpProperty, 4>, LockRank::None> m_coredump_properties {};
NonnullLockRefPtrVector<Thread> m_threads_for_coredump;
mutable LockRefPtr<ProcessProcFSTraits> m_procfs_traits;
@@ -920,7 +920,7 @@ private:
public:
using List = IntrusiveListRelaxedConst<&Process::m_list_node>;
- static SpinlockProtected<Process::List>& all_instances();
+ static SpinlockProtected<Process::List, LockRank::None>& all_instances();
};
// Note: Process object should be 2 pages of 4096 bytes each.
@@ -929,7 +929,7 @@ public:
// The second page is being used exclusively for write-protected values.
static_assert(AssertSize<Process, (PAGE_SIZE * 2)>());
-extern RecursiveSpinlock g_profiling_lock;
+extern RecursiveSpinlock<LockRank::None> g_profiling_lock;
template<IteratorFunction<Thread&> Callback>
inline IterationDecision Process::for_each_thread(Callback callback)
diff --git a/Kernel/ProcessExposed.cpp b/Kernel/ProcessExposed.cpp
index d9f9315f48..80b091e0a3 100644
--- a/Kernel/ProcessExposed.cpp
+++ b/Kernel/ProcessExposed.cpp
@@ -14,7 +14,7 @@
namespace Kernel {
-static Spinlock s_index_lock { LockRank::None };
+static Spinlock<LockRank::None> s_index_lock {};
static InodeIndex s_next_inode_index = 0;
namespace SegmentedProcFSIndex {
diff --git a/Kernel/ProcessGroup.cpp b/Kernel/ProcessGroup.cpp
index 7463ed41a6..f86b7c1473 100644
--- a/Kernel/ProcessGroup.cpp
+++ b/Kernel/ProcessGroup.cpp
@@ -10,9 +10,9 @@
namespace Kernel {
-static Singleton<SpinlockProtected<ProcessGroup::List>> s_process_groups;
+static Singleton<SpinlockProtected<ProcessGroup::List, LockRank::None>> s_process_groups;
-SpinlockProtected<ProcessGroup::List>& process_groups()
+SpinlockProtected<ProcessGroup::List, LockRank::None>& process_groups()
{
return *s_process_groups;
}
diff --git a/Kernel/ProcessGroup.h b/Kernel/ProcessGroup.h
index 8ab9b55134..69a52d2cb3 100644
--- a/Kernel/ProcessGroup.h
+++ b/Kernel/ProcessGroup.h
@@ -44,6 +44,6 @@ public:
using List = IntrusiveList<&ProcessGroup::m_list_node>;
};
-SpinlockProtected<ProcessGroup::List>& process_groups();
+SpinlockProtected<ProcessGroup::List, LockRank::None>& process_groups();
}
diff --git a/Kernel/Random.h b/Kernel/Random.h
index b5cb9f087d..2ae6bd91f1 100644
--- a/Kernel/Random.h
+++ b/Kernel/Random.h
@@ -82,7 +82,7 @@ public:
return is_seeded() || m_p0_len >= reseed_threshold;
}
- Spinlock& get_lock() { return m_lock; }
+ Spinlock<LockRank::None>& get_lock() { return m_lock; }
private:
void reseed()
@@ -117,7 +117,7 @@ private:
size_t m_p0_len { 0 };
ByteBuffer m_key;
HashType m_pools[pool_count];
- Spinlock m_lock { LockRank::None };
+ Spinlock<LockRank::None> m_lock {};
};
class KernelRng : public FortunaPRNG<Crypto::Cipher::AESCipher, Crypto::Hash::SHA256, 256> {
diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp
index 817e02288b..15c3d110f0 100644
--- a/Kernel/Scheduler.cpp
+++ b/Kernel/Scheduler.cpp
@@ -21,7 +21,7 @@
namespace Kernel {
-RecursiveSpinlock g_scheduler_lock { LockRank::None };
+RecursiveSpinlock<LockRank::None> g_scheduler_lock {};
static u32 time_slice_for(Thread const& thread)
{
@@ -46,9 +46,9 @@ struct ThreadReadyQueues {
Array<ThreadReadyQueue, count> queues;
};
-static Singleton<SpinlockProtected<ThreadReadyQueues>> g_ready_queues;
+static Singleton<SpinlockProtected<ThreadReadyQueues, LockRank::None>> g_ready_queues;
-static SpinlockProtected<TotalTimeScheduled> g_total_time_scheduled { LockRank::None };
+static SpinlockProtected<TotalTimeScheduled, LockRank::None> g_total_time_scheduled {};
static void dump_thread_list(bool = false);
diff --git a/Kernel/Scheduler.h b/Kernel/Scheduler.h
index ef15c3eb85..ae7b6a5783 100644
--- a/Kernel/Scheduler.h
+++ b/Kernel/Scheduler.h
@@ -22,7 +22,7 @@ struct RegisterState;
extern Thread* g_finalizer;
extern WaitQueue* g_finalizer_wait_queue;
extern Atomic<bool> g_finalizer_has_work;
-extern RecursiveSpinlock g_scheduler_lock;
+extern RecursiveSpinlock<LockRank::None> g_scheduler_lock;
struct TotalTimeScheduled {
u64 total { 0 };
diff --git a/Kernel/Storage/ATA/AHCI/Controller.h b/Kernel/Storage/ATA/AHCI/Controller.h
index aacd58d181..b4916b197d 100644
--- a/Kernel/Storage/ATA/AHCI/Controller.h
+++ b/Kernel/Storage/ATA/AHCI/Controller.h
@@ -60,6 +60,6 @@ private:
// Note: This lock is intended to be locked when doing changes to HBA registers
// that affect its core functionality in a manner that controls all attached storage devices
// to the HBA SATA ports.
- mutable Spinlock m_hba_control_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_hba_control_lock {};
};
}
diff --git a/Kernel/Storage/ATA/AHCI/Port.h b/Kernel/Storage/ATA/AHCI/Port.h
index 5c3f91df39..21df462b6a 100644
--- a/Kernel/Storage/ATA/AHCI/Port.h
+++ b/Kernel/Storage/ATA/AHCI/Port.h
@@ -107,7 +107,7 @@ private:
EntropySource m_entropy_source;
LockRefPtr<AsyncBlockDeviceRequest> m_current_request;
- Spinlock m_hard_lock { LockRank::None };
+ Spinlock<LockRank::None> m_hard_lock {};
Mutex m_lock { "AHCIPort"sv };
mutable bool m_wait_for_completion { false };
diff --git a/Kernel/Storage/ATA/ATAPort.h b/Kernel/Storage/ATA/ATAPort.h
index 0b576f403d..bb876cad7f 100644
--- a/Kernel/Storage/ATA/ATAPort.h
+++ b/Kernel/Storage/ATA/ATAPort.h
@@ -135,7 +135,7 @@ protected:
}
mutable Mutex m_lock;
- Spinlock m_hard_lock { LockRank::None };
+ Spinlock<LockRank::None> m_hard_lock {};
EntropySource m_entropy_source;
diff --git a/Kernel/Storage/NVMe/NVMeQueue.h b/Kernel/Storage/NVMe/NVMeQueue.h
index e58a06765e..2c1afddf53 100644
--- a/Kernel/Storage/NVMe/NVMeQueue.h
+++ b/Kernel/Storage/NVMe/NVMeQueue.h
@@ -56,10 +56,10 @@ private:
}
protected:
- Spinlock m_cq_lock { LockRank::Interrupts };
+ Spinlock<LockRank::Interrupts> m_cq_lock {};
LockRefPtr<AsyncBlockDeviceRequest> m_current_request;
NonnullOwnPtr<Memory::Region> m_rw_dma_region;
- Spinlock m_request_lock { LockRank::None };
+ Spinlock<LockRank::None> m_request_lock {};
private:
u16 m_qid {};
@@ -69,7 +69,7 @@ private:
u16 m_cq_head {};
bool m_admin_queue { false };
u32 m_qdepth {};
- Spinlock m_sq_lock { LockRank::Interrupts };
+ Spinlock<LockRank::Interrupts> m_sq_lock {};
OwnPtr<Memory::Region> m_cq_dma_region;
NonnullRefPtrVector<Memory::PhysicalPage> m_cq_dma_page;
Span<NVMeSubmission> m_sqe_array;
diff --git a/Kernel/Syscalls/futex.cpp b/Kernel/Syscalls/futex.cpp
index 6b12bd584a..b88ed5deaa 100644
--- a/Kernel/Syscalls/futex.cpp
+++ b/Kernel/Syscalls/futex.cpp
@@ -13,7 +13,7 @@
namespace Kernel {
-static Singleton<SpinlockProtected<HashMap<GlobalFutexKey, NonnullLockRefPtr<FutexQueue>>>> s_global_futex_queues;
+static Singleton<SpinlockProtected<HashMap<GlobalFutexKey, NonnullLockRefPtr<FutexQueue>>, LockRank::None>> s_global_futex_queues;
void Process::clear_futex_queues_on_exec()
{
diff --git a/Kernel/TTY/ConsoleManagement.h b/Kernel/TTY/ConsoleManagement.h
index ed890d85a9..675c931228 100644
--- a/Kernel/TTY/ConsoleManagement.h
+++ b/Kernel/TTY/ConsoleManagement.h
@@ -34,13 +34,13 @@ public:
NonnullLockRefPtr<VirtualConsole> first_tty() const { return m_consoles[0]; }
NonnullLockRefPtr<VirtualConsole> debug_tty() const { return m_consoles[1]; }
- RecursiveSpinlock& tty_write_lock() { return m_tty_write_lock; }
+ RecursiveSpinlock<LockRank::None>& tty_write_lock() { return m_tty_write_lock; }
private:
NonnullLockRefPtrVector<VirtualConsole, s_max_virtual_consoles> m_consoles;
VirtualConsole* m_active_console { nullptr };
- Spinlock m_lock { LockRank::None };
- RecursiveSpinlock m_tty_write_lock { LockRank::None };
+ Spinlock<LockRank::None> m_lock {};
+ RecursiveSpinlock<LockRank::None> m_tty_write_lock {};
};
};
diff --git a/Kernel/TTY/PTYMultiplexer.h b/Kernel/TTY/PTYMultiplexer.h
index 18c21e1000..c9da6ddbe0 100644
--- a/Kernel/TTY/PTYMultiplexer.h
+++ b/Kernel/TTY/PTYMultiplexer.h
@@ -35,7 +35,7 @@ private:
virtual StringView class_name() const override { return "PTYMultiplexer"sv; }
static constexpr size_t max_pty_pairs = 64;
- SpinlockProtected<Vector<unsigned, max_pty_pairs>> m_freelist { LockRank::None };
+ SpinlockProtected<Vector<unsigned, max_pty_pairs>, LockRank::None> m_freelist {};
};
}
diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp
index c3865dbb05..e2b0921d51 100644
--- a/Kernel/TTY/SlavePTY.cpp
+++ b/Kernel/TTY/SlavePTY.cpp
@@ -12,9 +12,9 @@
namespace Kernel {
-static Singleton<SpinlockProtected<SlavePTY::List>> s_all_instances;
+static Singleton<SpinlockProtected<SlavePTY::List, LockRank::None>> s_all_instances;
-SpinlockProtected<SlavePTY::List>& SlavePTY::all_instances()
+SpinlockProtected<SlavePTY::List, LockRank::None>& SlavePTY::all_instances()
{
return s_all_instances;
}
diff --git a/Kernel/TTY/SlavePTY.h b/Kernel/TTY/SlavePTY.h
index c576e0a72a..585c2f11a2 100644
--- a/Kernel/TTY/SlavePTY.h
+++ b/Kernel/TTY/SlavePTY.h
@@ -52,7 +52,7 @@ private:
public:
using List = IntrusiveList<&SlavePTY::m_list_node>;
- static SpinlockProtected<SlavePTY::List>& all_instances();
+ static SpinlockProtected<SlavePTY::List, LockRank::None>& all_instances();
};
}
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp
index a9f2b79481..f7fcf51fbd 100644
--- a/Kernel/Thread.cpp
+++ b/Kernel/Thread.cpp
@@ -33,9 +33,9 @@
namespace Kernel {
-static Singleton<SpinlockProtected<Thread::GlobalList>> s_list;
+static Singleton<SpinlockProtected<Thread::GlobalList, LockRank::None>> s_list;
-SpinlockProtected<Thread::GlobalList>& Thread::all_instances()
+SpinlockProtected<Thread::GlobalList, LockRank::None>& Thread::all_instances()
{
return *s_list;
}
@@ -215,7 +215,7 @@ Thread::BlockResult Thread::block_impl(BlockTimeout const& timeout, Blocker& blo
return result;
}
-void Thread::block(Kernel::Mutex& lock, SpinlockLocker<Spinlock>& lock_lock, u32 lock_count)
+void Thread::block(Kernel::Mutex& lock, SpinlockLocker<Spinlock<LockRank::None>>& lock_lock, u32 lock_count)
{
VERIFY(!Processor::current_in_irq());
VERIFY(this == Thread::current());
diff --git a/Kernel/Thread.h b/Kernel/Thread.h
index ab4f59fa0c..6652094cd0 100644
--- a/Kernel/Thread.h
+++ b/Kernel/Thread.h
@@ -298,7 +298,7 @@ public:
void set_blocker_set_raw_locked(BlockerSet* blocker_set) { m_blocker_set = blocker_set; }
// FIXME: Figure out whether this can be Thread.
- mutable RecursiveSpinlock m_lock { LockRank::None };
+ mutable RecursiveSpinlock<LockRank::None> m_lock {};
private:
BlockerSet* m_blocker_set { nullptr };
@@ -417,7 +417,7 @@ public:
}
// FIXME: Check whether this can be Thread.
- mutable Spinlock m_lock { LockRank::None };
+ mutable Spinlock<LockRank::None> m_lock {};
private:
Vector<BlockerInfo, 4> m_blockers;
@@ -812,7 +812,7 @@ public:
}
}
- void block(Kernel::Mutex&, SpinlockLocker<Spinlock>&, u32);
+ void block(Kernel::Mutex&, SpinlockLocker<Spinlock<LockRank::None>>&, u32);
template<typename BlockerType, class... Args>
BlockResult block(BlockTimeout const& timeout, Args&&... args)
@@ -1003,7 +1003,7 @@ public:
TrapFrame*& current_trap() { return m_current_trap; }
TrapFrame const* const& current_trap() const { return m_current_trap; }
- RecursiveSpinlock& get_lock() const { return m_lock; }
+ RecursiveSpinlock<LockRank::Thread>& get_lock() const { return m_lock; }
#if LOCK_DEBUG
void holding_lock(Mutex& lock, int refs_delta, LockLocation const& location)
@@ -1164,8 +1164,8 @@ private:
void relock_process(LockMode, u32);
void reset_fpu_state();
- mutable RecursiveSpinlock m_lock { LockRank::Thread };
- mutable RecursiveSpinlock m_block_lock { LockRank::None };
+ mutable RecursiveSpinlock<LockRank::Thread> m_lock {};
+ mutable RecursiveSpinlock<LockRank::None> m_block_lock {};
NonnullLockRefPtr<Process> m_process;
ThreadID m_tid { -1 };
ThreadRegisters m_regs {};
@@ -1199,7 +1199,7 @@ private:
Kernel::Mutex* m_blocking_mutex { nullptr };
u32 m_lock_requested_count { 0 };
IntrusiveListNode<Thread> m_blocked_threads_list_node;
- LockRank m_lock_rank_mask { LockRank::None };
+ LockRank m_lock_rank_mask {};
bool m_allocation_enabled { true };
// FIXME: remove this after annihilating Process::m_big_lock
@@ -1207,7 +1207,7 @@ private:
#if LOCK_DEBUG
Atomic<u32> m_holding_locks { 0 };
- Spinlock m_holding_locks_lock { LockRank::None };
+ Spinlock<LockRank::None> m_holding_locks_lock {};
Vector<HoldingLockInfo> m_holding_locks_list;
#endif
@@ -1267,7 +1267,7 @@ public:
using ListInProcess = IntrusiveList<&Thread::m_process_thread_list_node>;
using GlobalList = IntrusiveList<&Thread::m_global_thread_list_node>;
- static SpinlockProtected<GlobalList>& all_instances();
+ static SpinlockProtected<GlobalList, LockRank::None>& all_instances();
};
AK_ENUM_BITWISE_OPERATORS(Thread::FileBlocker::BlockFlags);
diff --git a/Kernel/TimerQueue.cpp b/Kernel/TimerQueue.cpp
index 9b788331ef..157af5c6d0 100644
--- a/Kernel/TimerQueue.cpp
+++ b/Kernel/TimerQueue.cpp
@@ -14,7 +14,7 @@
namespace Kernel {
static Singleton<TimerQueue> s_the;
-static Spinlock g_timerqueue_lock { LockRank::None };
+static Spinlock<LockRank::None> g_timerqueue_lock {};
Time Timer::remaining() const
{
diff --git a/Kernel/WorkQueue.h b/Kernel/WorkQueue.h
index 932d434ff6..ab35824666 100644
--- a/Kernel/WorkQueue.h
+++ b/Kernel/WorkQueue.h
@@ -63,7 +63,7 @@ private:
LockRefPtr<Thread> m_thread;
WaitQueue m_wait_queue;
- SpinlockProtected<IntrusiveList<&WorkItem::m_node>> m_items { LockRank::None };
+ SpinlockProtected<IntrusiveList<&WorkItem::m_node>, LockRank::None> m_items {};
};
}
diff --git a/Kernel/kprintf.cpp b/Kernel/kprintf.cpp
index ce21cd6952..6fe2d22a1f 100644
--- a/Kernel/kprintf.cpp
+++ b/Kernel/kprintf.cpp
@@ -29,7 +29,7 @@ extern Atomic<Graphics::Console*> g_boot_console;
static bool s_serial_debug_enabled;
// A recursive spinlock allows us to keep writing in the case where a
// page fault happens in the middle of a dbgln(), etc
-static RecursiveSpinlock s_log_lock { LockRank::None };
+static RecursiveSpinlock<LockRank::None> s_log_lock {};
void set_serial_debug_enabled(bool desired_state)
{