mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:57:46 +00:00
Kernel: Fix some Lock problems and VERIFY statements
When a Lock blocks (e.g. due to a mode mismatch or because someone else holds it) the lock mode will be updated to what was requested. There were also some cases where restoring locks may have not worked as intended as it may have been held already by the same thread. Fixes #8787
This commit is contained in:
parent
22a588d394
commit
710cf14c55
2 changed files with 110 additions and 35 deletions
|
@ -41,7 +41,20 @@ public:
|
|||
|
||||
void unlock();
|
||||
[[nodiscard]] Mode force_unlock_if_locked(u32&);
|
||||
[[nodiscard]] bool is_locked() const { return m_mode != Mode::Unlocked; }
|
||||
[[nodiscard]] bool is_locked() const
|
||||
{
|
||||
ScopedSpinLock lock(m_lock);
|
||||
return m_mode != Mode::Unlocked;
|
||||
}
|
||||
[[nodiscard]] bool own_lock() const
|
||||
{
|
||||
ScopedSpinLock lock(m_lock);
|
||||
if (m_mode == Mode::Exclusive)
|
||||
return m_holder == Thread::current();
|
||||
if (m_mode == Mode::Shared)
|
||||
return m_shared_holders.contains(Thread::current());
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] const char* name() const { return m_name; }
|
||||
|
||||
|
@ -89,7 +102,7 @@ private:
|
|||
BlockedThreadList m_blocked_threads_list_exclusive;
|
||||
BlockedThreadList m_blocked_threads_list_shared;
|
||||
|
||||
SpinLock<u8> m_lock;
|
||||
mutable SpinLock<u8> m_lock;
|
||||
};
|
||||
|
||||
class Locker {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue