Commit 0144d1d2 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-26720: rw_lock: Prefer fetch_sub() to fetch_and()

rw_lock::write_unlock(): Revert part of
commit d46b4248 (MDEV-24142)
to make the IA-32 and AMD64 implementation faster.
parent d301cc8e
...@@ -196,8 +196,12 @@ class rw_lock ...@@ -196,8 +196,12 @@ class rw_lock
/** Release an exclusive lock */ /** Release an exclusive lock */
void write_unlock() void write_unlock()
{ {
IF_DBUG_ASSERT(auto l=,) /* Below, we use fetch_sub(WRITER) instead of fetch_and(~WRITER).
lock.fetch_and(~WRITER, std::memory_order_release); The reason is that on IA-32 and AMD64 it translates into the 80486
instruction LOCK XADD, while fetch_and() translates into a loop
around LOCK CMPXCHG. For other ISA either form should be fine. */
static_assert(WRITER == 1U << 31, "compatibility");
IF_DBUG_ASSERT(auto l=,) lock.fetch_sub(WRITER, std::memory_order_release);
/* the write lock must have existed */ /* the write lock must have existed */
#ifdef SUX_LOCK_GENERIC #ifdef SUX_LOCK_GENERIC
DBUG_ASSERT((l & (WRITER | UPDATER)) == WRITER); DBUG_ASSERT((l & (WRITER | UPDATER)) == WRITER);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment