Commit adc30eca authored by Sergey Vojtovich's avatar Sergey Vojtovich

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.
parent d46b3c99
...@@ -167,21 +167,24 @@ struct TTASFutexMutex { ...@@ -167,21 +167,24 @@ struct TTASFutexMutex {
~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 /** 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, const char*, uint32_t) UNIV_NOTHROW 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. */ /** 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_a(m_lock_word == MUTEX_STATE_UNLOCKED); ut_ad(m_lock_word.load(std::memory_order_relaxed)
== MUTEX_STATE_UNLOCKED);
} }
/** Acquire the mutex. /** Acquire the mutex.
...@@ -202,9 +205,8 @@ struct TTASFutexMutex { ...@@ -202,9 +205,8 @@ struct TTASFutexMutex {
} }
for (n_waits= 0;; n_waits++) { for (n_waits= 0;; n_waits++) {
if (my_atomic_fas32_explicit(&m_lock_word, if (m_lock_word.exchange(MUTEX_STATE_WAITERS,
MUTEX_STATE_WAITERS, std::memory_order_acquire)
MY_MEMORY_ORDER_ACQUIRE)
== MUTEX_STATE_UNLOCKED) { == MUTEX_STATE_UNLOCKED) {
break; break;
} }
...@@ -220,9 +222,8 @@ struct TTASFutexMutex { ...@@ -220,9 +222,8 @@ struct TTASFutexMutex {
/** Release the mutex. */ /** Release the mutex. */
void exit() UNIV_NOTHROW void exit() UNIV_NOTHROW
{ {
if (my_atomic_fas32_explicit(&m_lock_word, if (m_lock_word.exchange(MUTEX_STATE_UNLOCKED,
MUTEX_STATE_UNLOCKED, std::memory_order_release)
MY_MEMORY_ORDER_RELEASE)
== MUTEX_STATE_WAITERS) { == MUTEX_STATE_WAITERS) {
syscall(SYS_futex, &m_lock_word, FUTEX_WAKE_PRIVATE, syscall(SYS_futex, &m_lock_word, FUTEX_WAKE_PRIVATE,
1, 0, 0, 0); 1, 0, 0, 0);
...@@ -234,10 +235,11 @@ struct TTASFutexMutex { ...@@ -234,10 +235,11 @@ struct TTASFutexMutex {
bool try_lock() UNIV_NOTHROW bool try_lock() UNIV_NOTHROW
{ {
int32 oldval = MUTEX_STATE_UNLOCKED; int32 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);
} }
/** @return non-const version of the policy */ /** @return non-const version of the policy */
...@@ -257,7 +259,7 @@ struct TTASFutexMutex { ...@@ -257,7 +259,7 @@ struct TTASFutexMutex {
/** lock_word is the target of the atomic test-and-set instruction /** lock_word is the target of the atomic test-and-set instruction
when atomic operations are enabled. */ when atomic operations are enabled. */
int32 m_lock_word; std::atomic<int32> m_lock_word;
}; };
#endif /* HAVE_IB_LINUX_FUTEX */ #endif /* HAVE_IB_LINUX_FUTEX */
......
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