mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:28:11 +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
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
private:
|
||||
explicit SysFSUSBBusDirectory(SysFSBusDirectory&);
|
||||
mutable Spinlock m_lock { LockRank::None };
|
||||
mutable Spinlock<LockRank::None> m_lock {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ private:
|
|||
|
||||
explicit SysFSCapsLockRemap(SysFSDirectory const&);
|
||||
|
||||
mutable Spinlock m_lock { LockRank::None };
|
||||
mutable Spinlock<LockRank::None> m_lock {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ private:
|
|||
|
||||
explicit SysFSDumpKmallocStacks(SysFSDirectory const&);
|
||||
|
||||
mutable Spinlock m_lock { LockRank::None };
|
||||
mutable Spinlock<LockRank::None> m_lock {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ VirtualFileSystem& VirtualFileSystem::the()
|
|||
}
|
||||
|
||||
UNMAP_AFTER_INIT VirtualFileSystem::VirtualFileSystem()
|
||||
: m_root_custody(LockRank::None)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue