summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-11-23 07:49:43 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2020-11-24 15:44:55 +0200
commit814bc213054a00591e00209e2995ec4004fd0922 (patch)
tree198ec4d0b239a100381667b40bfeeb684dbacc23
parent0bee3b8d651a15d3a498508782302e939a2e1af8 (diff)
downloadmariadb-git-814bc213054a00591e00209e2995ec4004fd0922.tar.gz
Cleanup: Use Atomic_relaxed for trx_t::state
For reading trx_t::state we can avoid acquiring trx_t::mutex. Atomic load and store should be similar to normal load and store on most instruction set architectures. The atomicity of the operation would merely prohibit the compiler from reordering some operations.
-rw-r--r--storage/innobase/include/trx0sys.h7
-rw-r--r--storage/innobase/include/trx0trx.h2
-rw-r--r--storage/innobase/lock/lock0lock.cc4
3 files changed, 4 insertions, 9 deletions
diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h
index 9fe6fcfa262..ba2e825f537 100644
--- a/storage/innobase/include/trx0sys.h
+++ b/storage/innobase/include/trx0sys.h
@@ -656,11 +656,8 @@ public:
trx->mutex is released, and it will have to be rechecked
by the caller after reacquiring the mutex.
*/
- trx_mutex_enter(trx);
- const trx_state_t state= trx->state;
- trx_mutex_exit(trx);
- if (state == TRX_STATE_COMMITTED_IN_MEMORY)
- trx= NULL;
+ if (trx->state == TRX_STATE_COMMITTED_IN_MEMORY)
+ trx= nullptr;
else
trx->reference();
}
diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h
index 2aa0ed1e0e3..aee6af8d8e5 100644
--- a/storage/innobase/include/trx0trx.h
+++ b/storage/innobase/include/trx0trx.h
@@ -787,7 +787,7 @@ public:
rw_trx_hash.
Transitions to COMMITTED are protected by trx_t::mutex. */
- trx_state_t state;
+ Atomic_relaxed<trx_state_t> state;
#ifdef WITH_WSREP
/** whether wsrep_on(mysql_thd) held at the start of transaction */
bool wsrep;
diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc
index 9d87a29626f..ed8c2a0a39b 100644
--- a/storage/innobase/lock/lock0lock.cc
+++ b/storage/innobase/lock/lock0lock.cc
@@ -5013,9 +5013,7 @@ static void lock_rec_other_trx_holds_expl(trx_t *caller_trx, trx_t *trx,
ut_ad(!page_rec_is_metadata(rec));
lock_mutex_enter();
ut_ad(trx->is_referenced());
- trx_mutex_enter(trx);
- const trx_state_t state = trx->state;
- trx_mutex_exit(trx);
+ const trx_state_t state{trx->state};
ut_ad(state != TRX_STATE_NOT_STARTED);
if (state == TRX_STATE_COMMITTED_IN_MEMORY)
{