mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +00:00
Kernel: Minor SpinLock improvements
This commit is contained in:
parent
e26e0445b5
commit
b4c9e85056
1 changed files with 7 additions and 9 deletions
|
@ -45,10 +45,8 @@ public:
|
||||||
{
|
{
|
||||||
u32 prev_flags;
|
u32 prev_flags;
|
||||||
Processor::current().enter_critical(prev_flags);
|
Processor::current().enter_critical(prev_flags);
|
||||||
BaseType expected = 0;
|
while (m_lock.exchange(1, AK::memory_order_acquire) != 0) {
|
||||||
while (!m_lock.compare_exchange_strong(expected, 1, AK::memory_order_acq_rel)) {
|
|
||||||
Processor::wait_check();
|
Processor::wait_check();
|
||||||
expected = 0;
|
|
||||||
}
|
}
|
||||||
return prev_flags;
|
return prev_flags;
|
||||||
}
|
}
|
||||||
|
@ -62,12 +60,12 @@ public:
|
||||||
|
|
||||||
ALWAYS_INLINE bool is_locked() const
|
ALWAYS_INLINE bool is_locked() const
|
||||||
{
|
{
|
||||||
return m_lock.load(AK::memory_order_consume) != 0;
|
return m_lock.load(AK::memory_order_relaxed) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE void initialize()
|
ALWAYS_INLINE void initialize()
|
||||||
{
|
{
|
||||||
m_lock.store(0, AK::memory_order_release);
|
m_lock.store(0, AK::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -101,7 +99,7 @@ public:
|
||||||
ALWAYS_INLINE void unlock(u32 prev_flags)
|
ALWAYS_INLINE void unlock(u32 prev_flags)
|
||||||
{
|
{
|
||||||
ASSERT(m_recursions > 0);
|
ASSERT(m_recursions > 0);
|
||||||
ASSERT(m_lock.load(AK::memory_order_consume) == FlatPtr(&Processor::current()));
|
ASSERT(m_lock.load(AK::memory_order_relaxed) == FlatPtr(&Processor::current()));
|
||||||
if (--m_recursions == 0)
|
if (--m_recursions == 0)
|
||||||
m_lock.store(0, AK::memory_order_release);
|
m_lock.store(0, AK::memory_order_release);
|
||||||
Processor::current().leave_critical(prev_flags);
|
Processor::current().leave_critical(prev_flags);
|
||||||
|
@ -109,17 +107,17 @@ public:
|
||||||
|
|
||||||
ALWAYS_INLINE bool is_locked() const
|
ALWAYS_INLINE bool is_locked() const
|
||||||
{
|
{
|
||||||
return m_lock.load(AK::memory_order_consume) != 0;
|
return m_lock.load(AK::memory_order_relaxed) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE bool own_lock() const
|
ALWAYS_INLINE bool own_lock() const
|
||||||
{
|
{
|
||||||
return m_lock.load(AK::memory_order_consume) == FlatPtr(&Processor::current());
|
return m_lock.load(AK::memory_order_relaxed) == FlatPtr(&Processor::current());
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE void initialize()
|
ALWAYS_INLINE void initialize()
|
||||||
{
|
{
|
||||||
m_lock.store(0, AK::memory_order_release);
|
m_lock.store(0, AK::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue