mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:58: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
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue