Skip to content

Commit 98a7fa0

Browse files
committed
MDEV-26720: optimize rw_lock for IA-32, AMD64
1 parent be803f0 commit 98a7fa0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

storage/innobase/include/rw_lock.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@ class rw_lock
3838

3939
/** Start waiting for an exclusive lock. */
4040
void write_lock_wait_start()
41-
{ lock.fetch_or(WRITER_WAITING, std::memory_order_relaxed); }
41+
{
42+
#if defined __GNUC__ && (defined __i386__ || defined __x86_64__)
43+
static_assert(WRITER_WAITING == 1U << 30, "compatibility");
44+
__asm__ __volatile__("lock btsl $30, %0" : "+m" (lock));
45+
#elif defined _MSC_VER && (defined _M_IX86 || defined _M_IX64)
46+
static_assert(WRITER_WAITING == 1U << 30, "compatibility");
47+
_interlockedbittestandset(reinterpret_cast<volatile long*>(&lock), 30);
48+
#else
49+
lock.fetch_or(WRITER_WAITING, std::memory_order_relaxed);
50+
#endif
51+
}
4252
/** Try to acquire a shared lock.
4353
@param l the value of the lock word
4454
@return whether the lock was acquired */

0 commit comments

Comments
 (0)