LibThread: Remove redundant r/w of atomic variable in Lock::lock() (#3013)

m_holder.compare_exchange_strong(expected, desired, ...)
will either successfully update the value to desired if == expected
or put the current value in expected otherwise.
This commit is contained in:
Muhammad Zahalqa 2020-08-06 18:50:25 +03:00 committed by GitHub
parent 4d9d054386
commit 5fe6c13e5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: sideshowbarker 2024-07-19 04:13:10 +09:00

View file

@ -72,12 +72,11 @@ ALWAYS_INLINE void Lock::lock()
}
for (;;) {
int expected = 0;
if (m_holder.compare_exchange_strong(expected, tid, AK::memory_order_acq_rel)) {
m_holder = tid;
if (m_holder.compare_exchange_strong(expected, tid, AK::memory_order_acq_rel)) {
m_level = 1;
return;
}
donate(m_holder);
donate(expected);
}
}