diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2018-12-28 14:24:22 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2018-12-29 14:02:15 +0400 |
commit | adc30ecab52c661689b18045a69b607ee6d42495 (patch) | |
tree | d3cfc927655889b00a96f8cb85739e083665808f | |
parent | d46b3c99b48522477c5c6017ad1bcf223903e59e (diff) | |
download | mariadb-git-adc30ecab52c661689b18045a69b607ee6d42495.tar.gz |
MDEV-17441 - InnoDB transition to C++11 atomics
Almost trivial TTASFutexMutex::m_lock_word transition. Since C++11
doesn't seem to allow mixed (atomic and non-atomic) access to atomic
variables, we have to perform all accesses atomically.
-rw-r--r-- | storage/innobase/include/ib0mutex.h | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/storage/innobase/include/ib0mutex.h b/storage/innobase/include/ib0mutex.h index 03b0e0bbf6c..e6b903a4ba4 100644 --- a/storage/innobase/include/ib0mutex.h +++ b/storage/innobase/include/ib0mutex.h @@ -167,21 +167,24 @@ struct TTASFutexMutex { ~TTASFutexMutex() { - ut_a(m_lock_word == MUTEX_STATE_UNLOCKED); + ut_ad(m_lock_word.load(std::memory_order_relaxed) + == MUTEX_STATE_UNLOCKED); } /** Called when the mutex is "created". Note: Not from the constructor but when the mutex is initialised. */ void init(latch_id_t, const char*, uint32_t) UNIV_NOTHROW { - ut_a(m_lock_word == MUTEX_STATE_UNLOCKED); + ut_ad(m_lock_word.load(std::memory_order_relaxed) + == MUTEX_STATE_UNLOCKED); } /** Destroy the mutex. */ void destroy() UNIV_NOTHROW { /* The destructor can be called at shutdown. */ - ut_a(m_lock_word == MUTEX_STATE_UNLOCKED); + ut_ad(m_lock_word.load(std::memory_order_relaxed) + == MUTEX_STATE_UNLOCKED); } /** Acquire the mutex. @@ -202,9 +205,8 @@ struct TTASFutexMutex { } for (n_waits= 0;; n_waits++) { - if (my_atomic_fas32_explicit(&m_lock_word, - MUTEX_STATE_WAITERS, - MY_MEMORY_ORDER_ACQUIRE) + if (m_lock_word.exchange(MUTEX_STATE_WAITERS, + std::memory_order_acquire) == MUTEX_STATE_UNLOCKED) { break; } @@ -220,9 +222,8 @@ struct TTASFutexMutex { /** Release the mutex. */ void exit() UNIV_NOTHROW { - if (my_atomic_fas32_explicit(&m_lock_word, - MUTEX_STATE_UNLOCKED, - MY_MEMORY_ORDER_RELEASE) + if (m_lock_word.exchange(MUTEX_STATE_UNLOCKED, + std::memory_order_release) == MUTEX_STATE_WAITERS) { syscall(SYS_futex, &m_lock_word, FUTEX_WAKE_PRIVATE, 1, 0, 0, 0); @@ -234,10 +235,11 @@ struct TTASFutexMutex { bool try_lock() UNIV_NOTHROW { int32 oldval = MUTEX_STATE_UNLOCKED; - return(my_atomic_cas32_strong_explicit(&m_lock_word, &oldval, - MUTEX_STATE_LOCKED, - MY_MEMORY_ORDER_ACQUIRE, - MY_MEMORY_ORDER_RELAXED)); + return m_lock_word.compare_exchange_strong( + oldval, + MUTEX_STATE_LOCKED, + std::memory_order_acquire, + std::memory_order_relaxed); } /** @return non-const version of the policy */ @@ -257,7 +259,7 @@ private: /** lock_word is the target of the atomic test-and-set instruction when atomic operations are enabled. */ - int32 m_lock_word; + std::atomic<int32> m_lock_word; }; #endif /* HAVE_IB_LINUX_FUTEX */ |