From 91503dfdcc51f558b89587566a0a2727c0a1329b Mon Sep 17 00:00:00 2001 From: "Debayan Ghosh, Qualcomm Datacenter Technologies, Inc" Date: Wed, 8 Nov 2017 06:23:28 +0000 Subject: [PATCH] InnoDB: Use CAS for Eventmutex trylock --- storage/innobase/include/ib0mutex.h | 13 +++++++------ storage/innobase/include/os0atomic.ic | 5 ++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/storage/innobase/include/ib0mutex.h b/storage/innobase/include/ib0mutex.h index 6cf40a6..ede0dc1 100644 --- a/storage/innobase/include/ib0mutex.h +++ b/storage/innobase/include/ib0mutex.h @@ -665,7 +665,7 @@ struct TTASEventMutex { bool try_lock() UNIV_NOTHROW { - return(tas_lock()); + return(cas_lock()); } /** Release the mutex. */ @@ -881,12 +881,13 @@ private: os_wmb; } - /** Try and acquire the lock using TestAndSet. + /** Try and acquire the lock using CompareAndSet. @return true if lock succeeded */ - bool tas_lock() UNIV_NOTHROW + bool cas_lock() UNIV_NOTHROW { - return(TAS(&m_lock_word, MUTEX_STATE_LOCKED) - == MUTEX_STATE_UNLOCKED); + /* Using a compare and swap over a Test and Set */ + return (CAS(&m_lock_word, MUTEX_STATE_UNLOCKED, MUTEX_STATE_LOCKED) + == MUTEX_STATE_UNLOCKED); } /** In theory __sync_lock_release should be used to release the lock. @@ -907,7 +908,7 @@ private: /** lock_word is the target of the atomic test-and-set instruction when atomic operations are enabled. */ - lock_word_t m_lock_word; + volatile lock_word_t m_lock_word; /** Set to 0 or 1. 1 if there are (or may be) threads waiting in the global wait array for this mutex to be released. */ diff --git a/storage/innobase/include/os0atomic.ic b/storage/innobase/include/os0atomic.ic index 1f1c460..5d9602e 100644 --- a/storage/innobase/include/os0atomic.ic +++ b/storage/innobase/include/os0atomic.ic @@ -176,9 +176,12 @@ os_atomic_val_compare_and_swap( /* Silence a compiler warning about unused ptr. */ (void) ptr; -#if defined(__powerpc__) || defined(__aarch64__) +#if defined(__powerpc__) __atomic_compare_exchange(ptr, &old_val, &new_val, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); +#elif defined(__aarch64__) + __atomic_compare_exchange(ptr, &old_val, &new_val, false, + __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); #else __atomic_compare_exchange(ptr, &old_val, &new_val, false, __ATOMIC_RELEASE, __ATOMIC_ACQUIRE); -- 1.8.3.1