Skip to content

Commit

Permalink
MDEV-26720: rw_lock: Prefer fetch_sub() to fetch_and()
Browse files Browse the repository at this point in the history
rw_lock::write_unlock(): Revert part of
commit d46b424 (MDEV-24142)
to make the IA-32 and AMD64 implementation faster.
  • Loading branch information
dr-m committed Oct 2, 2021
1 parent d301cc8 commit 0144d1d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions storage/innobase/include/rw_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,12 @@ class rw_lock
/** Release an exclusive lock */
void write_unlock()
{
IF_DBUG_ASSERT(auto l=,)
lock.fetch_and(~WRITER, std::memory_order_release);
/* Below, we use fetch_sub(WRITER) instead of fetch_and(~WRITER).
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 */
#ifdef SUX_LOCK_GENERIC
DBUG_ASSERT((l & (WRITER | UPDATER)) == WRITER);
Expand Down

0 comments on commit 0144d1d

Please sign in to comment.