Commit fbe2a5b7 authored by Sergey Vojtovich's avatar Sergey Vojtovich

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

Almost trivial ReadView::m_state 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 28d62739
......@@ -41,7 +41,6 @@ Created 11/5/1995 Heikki Tuuri
#include "os0proc.h"
#include "log0log.h"
#include "srv0srv.h"
#include "my_atomic.h"
#include <ostream>
// Forward declaration
......
......@@ -66,7 +66,14 @@ class ReadView
Close view:
READ_VIEW_STATE_OPEN -> READ_VIEW_STATE_CLOSED
*/
int32_t m_state;
std::atomic<uint32_t> m_state;
/** m_state getter for ReadView owner thread */
uint32_t state() const
{
return m_state.load(std::memory_order_relaxed);
}
public:
......@@ -134,35 +141,36 @@ class ReadView
Closes the view.
View becomes not visible to purge thread.
This method is intended to be called by ReadView owner thread, thus
m_state cannot change.
*/
void close()
{
ut_ad(m_state == READ_VIEW_STATE_CLOSED ||
m_state == READ_VIEW_STATE_OPEN);
if (m_state == READ_VIEW_STATE_OPEN)
my_atomic_store32_explicit(&m_state, READ_VIEW_STATE_CLOSED,
MY_MEMORY_ORDER_RELAXED);
ut_ad(state() == READ_VIEW_STATE_CLOSED ||
state() == READ_VIEW_STATE_OPEN);
m_state.store(READ_VIEW_STATE_CLOSED, std::memory_order_relaxed);
}
/** m_state getter for trx_sys::clone_oldest_view() trx_sys::size(). */
int32_t get_state() const
uint32_t get_state() const
{
return my_atomic_load32_explicit(const_cast<int32*>(&m_state),
MY_MEMORY_ORDER_ACQUIRE);
return m_state.load(std::memory_order_acquire);
}
/**
Returns true if view is open.
Only used by view owner thread, thus we can omit atomic operations.
This method is intended to be called by ReadView owner thread, thus
m_state cannot change.
*/
bool is_open() const
{
ut_ad(m_state == READ_VIEW_STATE_OPEN ||
m_state == READ_VIEW_STATE_CLOSED);
return m_state == READ_VIEW_STATE_OPEN;
ut_ad(state() == READ_VIEW_STATE_OPEN ||
state() == READ_VIEW_STATE_CLOSED);
return state() == READ_VIEW_STATE_OPEN;
}
......
......@@ -45,7 +45,6 @@ Created 1/20/1994 Heikki Tuuri
#include <stdarg.h>
#include <string>
#include <my_atomic.h>
/** Index name prefix in fast index creation, as a string constant */
#define TEMP_INDEX_PREFIX_STR "\377"
......
......@@ -200,7 +200,7 @@ inline void ReadView::snapshot(trx_t *trx)
void ReadView::open(trx_t *trx)
{
ut_ad(this == &trx->read_view);
switch (m_state)
switch (state())
{
case READ_VIEW_STATE_OPEN:
ut_ad(!srv_read_only_mode);
......@@ -254,8 +254,7 @@ void ReadView::open(trx_t *trx)
*/
mutex_enter(&trx_sys.mutex);
mutex_exit(&trx_sys.mutex);
my_atomic_store32_explicit(&m_state, READ_VIEW_STATE_SNAPSHOT,
MY_MEMORY_ORDER_RELAXED);
m_state.store(READ_VIEW_STATE_SNAPSHOT, std::memory_order_relaxed);
break;
default:
ut_ad(0);
......@@ -264,8 +263,7 @@ void ReadView::open(trx_t *trx)
snapshot(trx);
reopen:
m_creator_trx_id= trx->id;
my_atomic_store32_explicit(&m_state, READ_VIEW_STATE_OPEN,
MY_MEMORY_ORDER_RELEASE);
m_state.store(READ_VIEW_STATE_OPEN, std::memory_order_release);
}
......@@ -284,7 +282,7 @@ void trx_sys_t::clone_oldest_view()
for (const trx_t *trx= UT_LIST_GET_FIRST(trx_list); trx;
trx= UT_LIST_GET_NEXT(trx_list, trx))
{
int32_t state;
uint32_t state;
while ((state= trx->read_view.get_state()) == READ_VIEW_STATE_SNAPSHOT)
ut_delay(1);
......
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