mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:57:34 +00:00
Kernel: Don't ref/unref the holder thread in Mutex
There was a whole bunch of ref counting churn coming from Mutex, which had a RefPtr<Thread> m_holder to (mostly) point at the thread holding the mutex. Since we never actually dereference the m_holder value, but only use it for identity checks against thread pointers, we can store it as an uintptr_t and skip the ref counting entirely. Threads can't die while holding a mutex anyway, so there's no risk of them going missing on us.
This commit is contained in:
parent
c3915e4058
commit
ed1253ab90
2 changed files with 26 additions and 31 deletions
|
@ -57,7 +57,7 @@ public:
|
|||
VERIFY(m_mode != Mode::Shared); // This method should only be used on exclusively-held locks
|
||||
if (m_mode == Mode::Unlocked)
|
||||
return false;
|
||||
return m_holder == Thread::current();
|
||||
return m_holder == bit_cast<uintptr_t>(Thread::current());
|
||||
}
|
||||
|
||||
[[nodiscard]] StringView name() const { return m_name; }
|
||||
|
@ -96,12 +96,11 @@ private:
|
|||
// lock it again. When locked in shared mode, any thread can do that.
|
||||
u32 m_times_locked { 0 };
|
||||
|
||||
// One of the threads that hold this lock, or nullptr. When locked in shared
|
||||
// mode, this is stored on best effort basis: nullptr value does *not* mean
|
||||
// The address of one of the threads that hold this lock, or 0.
|
||||
// When locked in shared mode, this is stored on best effort basis: 0 does *not* mean
|
||||
// the lock is unlocked, it just means we don't know which threads hold it.
|
||||
// When locked exclusively, this is always the one thread that holds the
|
||||
// lock.
|
||||
RefPtr<Thread> m_holder;
|
||||
// When locked exclusively, this is always the one thread that holds the lock.
|
||||
uintptr_t m_holder { 0 };
|
||||
size_t m_shared_holders { 0 };
|
||||
|
||||
struct BlockedThreadLists {
|
||||
|
@ -124,7 +123,7 @@ private:
|
|||
mutable Spinlock<LockRank::None> m_lock {};
|
||||
|
||||
#if LOCK_SHARED_UPGRADE_DEBUG
|
||||
HashMap<Thread*, u32> m_shared_holders_map;
|
||||
HashMap<uintptr_t, u32> m_shared_holders_map;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue