diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2018-12-28 15:23:54 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2018-12-29 14:02:15 +0400 |
commit | fbe2a5b7d691f9742053623517e7fd8639562e63 (patch) | |
tree | f6918afae6cbf4e3ce790347e28753074c672d1e | |
parent | 28d627392b3ea39ceefd8df7451813da660bf19d (diff) | |
download | mariadb-git-fbe2a5b7d691f9742053623517e7fd8639562e63.tar.gz |
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.
-rw-r--r-- | storage/innobase/include/buf0buf.h | 1 | ||||
-rw-r--r-- | storage/innobase/include/read0types.h | 34 | ||||
-rw-r--r-- | storage/innobase/include/ut0ut.h | 1 | ||||
-rw-r--r-- | storage/innobase/read/read0read.cc | 10 |
4 files changed, 25 insertions, 21 deletions
diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 37fd0d7a6e1..75071ebce2f 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -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 diff --git a/storage/innobase/include/read0types.h b/storage/innobase/include/read0types.h index 52338889c47..5cd8e1740a7 100644 --- a/storage/innobase/include/read0types.h +++ b/storage/innobase/include/read0types.h @@ -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 @@ loop: 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; } diff --git a/storage/innobase/include/ut0ut.h b/storage/innobase/include/ut0ut.h index 813b5f5c198..6ca661378b1 100644 --- a/storage/innobase/include/ut0ut.h +++ b/storage/innobase/include/ut0ut.h @@ -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" diff --git a/storage/innobase/read/read0read.cc b/storage/innobase/read/read0read.cc index 470c8ec63f1..df2406fb0e4 100644 --- a/storage/innobase/read/read0read.cc +++ b/storage/innobase/read/read0read.cc @@ -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); |