1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +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:
kleines Filmröllchen 2022-11-09 11:39:58 +01:00 committed by Brian Gianforcaro
parent 363cc12146
commit a6a439243f
94 changed files with 235 additions and 259 deletions

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