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