From 24449c2a07976b6b5b89c2fbe9d6f7267bc6a607 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Mon, 7 Dec 2015 19:37:00 +0300 Subject: [PATCH] mdbx: avoid tsan-trap in mdb_txn_renew0() by me_live_reader. Change-Id: I70f173d3e77c9cc84881c86e8fc64ae2a4906f0b --- mdb.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mdb.c b/mdb.c index 09eabe50..1cea45f1 100644 --- a/mdb.c +++ b/mdb.c @@ -2773,16 +2773,19 @@ mdb_txn_renew0(MDB_txn *txn, unsigned flags) pthread_t tid = pthread_self(); pthread_mutex_t *rmutex = MDB_MUTEX(env, r); - if (unlikely(!env->me_live_reader)) { - rc = mdb_reader_pid(env, F_SETLK, pid); - if (unlikely(rc != MDB_SUCCESS)) - return rc; - env->me_live_reader = 1; - } - rc = mdb_mutex_lock(env, rmutex); if (unlikely(rc != MDB_SUCCESS)) return rc; + + if (unlikely(!env->me_live_reader)) { + rc = mdb_reader_pid(env, F_SETLK, pid); + if (unlikely(rc != MDB_SUCCESS)) { + mdb_mutex_unlock(env, rmutex); + return rc; + } + env->me_live_reader = 1; + } + nr = env->me_txns->mti_numreaders; for (i=0; ime_txns->mti_readers[i].mr_pid == 0)