Commit 601f45fd authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-17441 - InnoDB transition to C++11 atomics

Almost trivial TTASMutex::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.
parent 2e5d3596
...@@ -277,40 +277,45 @@ struct TTASMutex { ...@@ -277,40 +277,45 @@ struct TTASMutex {
~TTASMutex() ~TTASMutex()
{ {
ut_ad(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 /** Called when the mutex is "created". Note: Not from the constructor
but when the mutex is initialised. */ but when the mutex is initialised. */
void init(latch_id_t) UNIV_NOTHROW void init(latch_id_t) UNIV_NOTHROW
{ {
ut_ad(m_lock_word == MUTEX_STATE_UNLOCKED); ut_ad(m_lock_word.load(std::memory_order_relaxed)
== MUTEX_STATE_UNLOCKED);
} }
/** Destroy the mutex. */ /** Destroy the mutex. */
void destroy() UNIV_NOTHROW void destroy() UNIV_NOTHROW
{ {
/* The destructor can be called at shutdown. */ /* The destructor can be called at shutdown. */
ut_ad(m_lock_word == MUTEX_STATE_UNLOCKED); ut_ad(m_lock_word.load(std::memory_order_relaxed)
== MUTEX_STATE_UNLOCKED);
} }
/** Try and lock the mutex. /** Try and lock the mutex.
@return true on success */ @return true on success */
bool try_lock() UNIV_NOTHROW bool try_lock() UNIV_NOTHROW
{ {
int32 oldval = MUTEX_STATE_UNLOCKED; uint32_t oldval = MUTEX_STATE_UNLOCKED;
return(my_atomic_cas32_strong_explicit(&m_lock_word, &oldval, return m_lock_word.compare_exchange_strong(
oldval,
MUTEX_STATE_LOCKED, MUTEX_STATE_LOCKED,
MY_MEMORY_ORDER_ACQUIRE, std::memory_order_acquire,
MY_MEMORY_ORDER_RELAXED)); std::memory_order_relaxed);
} }
/** Release the mutex. */ /** Release the mutex. */
void exit() UNIV_NOTHROW void exit() UNIV_NOTHROW
{ {
ut_ad(m_lock_word == MUTEX_STATE_LOCKED); ut_ad(m_lock_word.load(std::memory_order_relaxed)
my_atomic_store32_explicit(&m_lock_word, MUTEX_STATE_UNLOCKED, == MUTEX_STATE_LOCKED);
MY_MEMORY_ORDER_RELEASE); m_lock_word.store(MUTEX_STATE_UNLOCKED,
std::memory_order_release);
} }
/** Acquire the mutex. /** Acquire the mutex.
...@@ -353,9 +358,8 @@ struct TTASMutex { ...@@ -353,9 +358,8 @@ struct TTASMutex {
/** Policy data */ /** Policy data */
MutexPolicy m_policy; MutexPolicy m_policy;
/** lock_word is the target of the atomic test-and-set instruction /** mutex state */
when atomic operations are enabled. */ std::atomic<uint32_t> m_lock_word;
int32 m_lock_word;
}; };
template <template <typename> class Policy = NoPolicy> template <template <typename> class Policy = NoPolicy>
......
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