mdbx: fix/refine mdbx_txn_end() and mdbx_txn_renew0().

This commit is contained in:
Leo Yuriev 2017-04-21 18:27:40 +03:00
parent c2087f186e
commit 99dd373215

View File

@ -2156,7 +2156,7 @@ static void mdbx_cursors_eot(MDB_txn *txn, unsigned merge) {
static int mdbx_txn_renew0(MDB_txn *txn, unsigned flags) { static int mdbx_txn_renew0(MDB_txn *txn, unsigned flags) {
MDB_env *env = txn->mt_env; MDB_env *env = txn->mt_env;
unsigned i, nr; unsigned i, nr;
int rc, new_notls = 0; int rc;
if (unlikely(env->me_pid != mdbx_getpid())) { if (unlikely(env->me_pid != mdbx_getpid())) {
env->me_flags |= MDB_FATAL_ERROR; env->me_flags |= MDB_FATAL_ERROR;
@ -2231,11 +2231,8 @@ static int mdbx_txn_renew0(MDB_txn *txn, unsigned flags) {
#endif #endif
mdbx_rdt_unlock(env); mdbx_rdt_unlock(env);
new_notls = MDB_END_SLOT /* == MDB_NOTLS */; if (likely(env->me_flags & MDB_ENV_TXKEY))
if (likely(env->me_flags & MDB_ENV_TXKEY)) {
mdbx_thread_rthc_set(env->me_txkey, r); mdbx_thread_rthc_set(env->me_txkey, r);
new_notls = 0;
}
} }
while ((env->me_flags & MDB_FATAL_ERROR) == 0) { while ((env->me_flags & MDB_FATAL_ERROR) == 0) {
@ -2322,7 +2319,7 @@ static int mdbx_txn_renew0(MDB_txn *txn, unsigned flags) {
} else { } else {
return MDB_SUCCESS; return MDB_SUCCESS;
} }
mdbx_txn_end(txn, new_notls /*0 or MDB_END_SLOT*/ | MDB_END_FAIL_BEGIN); mdbx_txn_end(txn, MDB_END_SLOT | MDB_END_FAIL_BEGIN);
return rc; return rc;
} }
@ -2527,12 +2524,11 @@ static int mdbx_txn_end(MDB_txn *txn, unsigned mode) {
mdbx_mutex_lock(&tsan_mutex); mdbx_mutex_lock(&tsan_mutex);
#endif #endif
txn->mt_u.reader->mr_txnid = ~(txnid_t)0; txn->mt_u.reader->mr_txnid = ~(txnid_t)0;
if (!(env->me_flags & MDB_NOTLS)) { if (mode & MDB_END_SLOT) {
txn->mt_u.reader = NULL; /* txn does not own reader */ if ((env->me_flags & MDB_ENV_TXKEY) == 0)
} else if (mode & MDB_END_SLOT) { txn->mt_u.reader->mr_pid = 0;
txn->mt_u.reader->mr_pid = 0;
txn->mt_u.reader = NULL; txn->mt_u.reader = NULL;
} /* else txn owns the slot until it does MDB_END_SLOT */ }
#ifdef __SANITIZE_THREAD__ #ifdef __SANITIZE_THREAD__
mdbx_mutex_unlock(&tsan_mutex); mdbx_mutex_unlock(&tsan_mutex);
#endif #endif