mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
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:
parent
363cc12146
commit
a6a439243f
94 changed files with 235 additions and 259 deletions
|
@ -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 {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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 {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue