1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

XID_cache_element::m_state transition to std::atomic

This commit is contained in:
Sergey Vojtovich
2018-12-29 00:44:34 +04:00
parent 9e37537c4e
commit 1e7df0e530

View File

@@ -5599,34 +5599,34 @@ class XID_cache_element
ACQUIRED and RECOVERED flags are cleared before element is deleted from ACQUIRED and RECOVERED flags are cleared before element is deleted from
hash in a spin loop, after last reference is released. hash in a spin loop, after last reference is released.
*/ */
int32 m_state; std::atomic<int32_t> m_state;
public: public:
static const int32 ACQUIRED= 1 << 30; static const int32 ACQUIRED= 1 << 30;
static const int32 RECOVERED= 1 << 29; static const int32 RECOVERED= 1 << 29;
XID_STATE *m_xid_state; XID_STATE *m_xid_state;
bool is_set(int32 flag) bool is_set(int32_t flag)
{ return my_atomic_load32_explicit(&m_state, MY_MEMORY_ORDER_RELAXED) & flag; } { return m_state.load(std::memory_order_relaxed) & flag; }
void set(int32 flag) void set(int32_t flag)
{ {
DBUG_ASSERT(!is_set(ACQUIRED | RECOVERED)); DBUG_ASSERT(!is_set(ACQUIRED | RECOVERED));
my_atomic_add32_explicit(&m_state, flag, MY_MEMORY_ORDER_RELAXED); m_state.fetch_add(flag, std::memory_order_relaxed);
} }
bool lock() bool lock()
{ {
int32 old= my_atomic_add32_explicit(&m_state, 1, MY_MEMORY_ORDER_ACQUIRE); int32_t old= m_state.fetch_add(1, std::memory_order_acquire);
if (old & (ACQUIRED | RECOVERED)) if (old & (ACQUIRED | RECOVERED))
return true; return true;
unlock(); unlock();
return false; return false;
} }
void unlock() void unlock()
{ my_atomic_add32_explicit(&m_state, -1, MY_MEMORY_ORDER_RELEASE); } { m_state.fetch_sub(1, std::memory_order_release); }
void mark_uninitialized() void mark_uninitialized()
{ {
int32 old= ACQUIRED; int32_t old= ACQUIRED;
while (!my_atomic_cas32_weak_explicit(&m_state, &old, 0, while (!m_state.compare_exchange_weak(old, 0,
MY_MEMORY_ORDER_RELAXED, std::memory_order_relaxed,
MY_MEMORY_ORDER_RELAXED)) std::memory_order_relaxed))
{ {
old&= ACQUIRED | RECOVERED; old&= ACQUIRED | RECOVERED;
(void) LF_BACKOFF(); (void) LF_BACKOFF();
@@ -5634,10 +5634,10 @@ public:
} }
bool acquire_recovered() bool acquire_recovered()
{ {
int32 old= RECOVERED; int32_t old= RECOVERED;
while (!my_atomic_cas32_weak_explicit(&m_state, &old, ACQUIRED | RECOVERED, while (!m_state.compare_exchange_weak(old, ACQUIRED | RECOVERED,
MY_MEMORY_ORDER_RELAXED, std::memory_order_relaxed,
MY_MEMORY_ORDER_RELAXED)) std::memory_order_relaxed))
{ {
if (!(old & RECOVERED) || (old & ACQUIRED)) if (!(old & RECOVERED) || (old & ACQUIRED))
return false; return false;