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.
This commit is contained in:
kleines Filmröllchen 2022-11-09 11:39:58 +01:00 committed by Brian Gianforcaro
parent 363cc12146
commit a6a439243f
Notes: sideshowbarker 2024-07-17 18:49:10 +09:00
94 changed files with 235 additions and 259 deletions

View file

@ -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

View file

@ -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 };

View file

@ -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;

View file

@ -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 };
};

View file

@ -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;

View file

@ -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 {};
};
}

View file

@ -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)
{
}

View file

@ -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;

View file

@ -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;
};
}

View file

@ -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;
};

View file

@ -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

View file

@ -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;
}

View file

@ -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();

View file

@ -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 {};
};
}

View file

@ -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;
};

View file

@ -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()
{

View file

@ -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;

View file

@ -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:

View file

@ -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;
};

View file

@ -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 {

View file

@ -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; }

View file

@ -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;
};

View file

@ -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 {};
};
}

View file

@ -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 {};
};
}

View file

@ -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;
}

View file

@ -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();
};
}

View file

@ -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;
};

View file

@ -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;
}

View file

@ -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();
};
}

View file

@ -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)
{
}

View file

@ -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;

View file

@ -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 {};
};
}

View file

@ -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 };

View file

@ -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()

View file

@ -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 {};
};
}

View file

@ -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 {};
};
}

View file

@ -27,7 +27,7 @@ public:
private:
explicit SysFSUSBBusDirectory(SysFSBusDirectory&);
mutable Spinlock m_lock { LockRank::None };
mutable Spinlock<LockRank::None> m_lock {};
};
}

View file

@ -25,7 +25,7 @@ private:
explicit SysFSCapsLockRemap(SysFSDirectory const&);
mutable Spinlock m_lock { LockRank::None };
mutable Spinlock<LockRank::None> m_lock {};
};
}

View file

@ -25,7 +25,7 @@ private:
explicit SysFSDumpKmallocStacks(SysFSDirectory const&);
mutable Spinlock m_lock { LockRank::None };
mutable Spinlock<LockRank::None> m_lock {};
};
}

View file

@ -39,7 +39,6 @@ VirtualFileSystem& VirtualFileSystem::the()
}
UNMAP_AFTER_INIT VirtualFileSystem::VirtualFileSystem()
: m_root_custody(LockRank::None)
{
}

View file

@ -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 {};
};
}

View file

@ -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;

View file

@ -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 {};
};
}

View file

@ -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 {};
};
}

View file

@ -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;

View file

@ -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;
};

View file

@ -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

View file

@ -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;

View file

@ -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 {};
};
}

View file

@ -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;
};
}

View file

@ -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)

View file

@ -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 };
};
}

View file

@ -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 {};
};
}

View file

@ -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.

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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>

View file

@ -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 };
};
}

View file

@ -78,7 +78,7 @@ private:
void uncommit_one();
private:
Spinlock m_lock { LockRank::None };
Spinlock<LockRank::None> m_lock {};
CommittedPhysicalPageSet m_committed_pages;
};

View file

@ -88,7 +88,6 @@ MemoryManager::GlobalData::GlobalData()
}
UNMAP_AFTER_INIT MemoryManager::MemoryManager()
: m_global_data(LockRank::None)
{
s_the = this;

View file

@ -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)

View file

@ -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);

View file

@ -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;

View file

@ -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();

View file

@ -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 {};

View file

@ -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;
};

View file

@ -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;
}

View file

@ -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>

View file

@ -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 };

View file

@ -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;
};

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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.

View file

@ -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)

View file

@ -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 {

View file

@ -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;
}

View file

@ -44,6 +44,6 @@ public:
using List = IntrusiveList<&ProcessGroup::m_list_node>;
};
SpinlockProtected<ProcessGroup::List>& process_groups();
SpinlockProtected<ProcessGroup::List, LockRank::None>& process_groups();
}

View file

@ -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> {

View file

@ -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);

View file

@ -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 };

View file

@ -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 {};
};
}

View file

@ -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 };

View file

@ -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;

View file

@ -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;

View file

@ -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()
{

View file

@ -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 {};
};
};

View file

@ -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 {};
};
}

View file

@ -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;
}

View file

@ -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();
};
}

View file

@ -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());

View file

@ -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);

View file

@ -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
{

View file

@ -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 {};
};
}

View file

@ -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)
{