Kernel: Minor Lock optimization

This commit is contained in:
Tom 2020-10-28 20:03:15 -06:00 committed by Andreas Kling
parent b4c9e85056
commit 66f46d03e4
Notes: sideshowbarker 2024-07-19 01:26:54 +09:00

View file

@ -52,8 +52,7 @@ void Lock::lock(Mode mode)
} }
auto current_thread = Thread::current(); auto current_thread = Thread::current();
for (;;) { for (;;) {
bool expected = false; if (m_lock.exchange(true, AK::memory_order_acq_rel) == false) {
if (m_lock.compare_exchange_strong(expected, true, AK::memory_order_acq_rel)) {
do { do {
// FIXME: Do not add new readers if writers are queued. // FIXME: Do not add new readers if writers are queued.
bool modes_dont_conflict = !modes_conflict(m_mode, mode); bool modes_dont_conflict = !modes_conflict(m_mode, mode);
@ -91,8 +90,7 @@ void Lock::unlock()
{ {
auto current_thread = Thread::current(); auto current_thread = Thread::current();
for (;;) { for (;;) {
bool expected = false; if (m_lock.exchange(true, AK::memory_order_acq_rel) == false) {
if (m_lock.compare_exchange_strong(expected, true, AK::memory_order_acq_rel)) {
ASSERT(m_times_locked); ASSERT(m_times_locked);
--m_times_locked; --m_times_locked;