From 4e5d5ef9354906dcc627aa35f41e83aee73930e6 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Sun, 6 Dec 2015 13:37:45 +0300 Subject: [PATCH] mdbx: avoid tsan-trap in mdb_meta_head_r(). Change-Id: I594c13e1fe908f8afdc663d349cfc4cf634bba77 --- mdb.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mdb.c b/mdb.c index 8f908b2c..c54f380c 100644 --- a/mdb.c +++ b/mdb.c @@ -1857,17 +1857,18 @@ static MDB_meta* mdb_meta_head_w(MDB_env *env) { return a; } -static MDB_meta* mdb_meta_head_r(MDB_env *env) { +static ATTRIBUTE_NO_SANITIZE_THREAD /* LY: avoid tsan-trap by meta->mm_txnid */ +MDB_meta* mdb_meta_head_r(MDB_env *env) { MDB_meta* a = METAPAGE_1(env); MDB_meta* b = METAPAGE_2(env), *h; txnid_t head_txnid; int loop = 0, rc; - do { + while(1) { head_txnid = env->me_txns->mti_txnid; mdb_assert(env, a->mm_txnid != b->mm_txnid || head_txnid == 0); - if (a->mm_txnid == head_txnid) + if (likely(a->mm_txnid == head_txnid)) return a; if (likely(b->mm_txnid == head_txnid)) return b; @@ -1877,9 +1878,13 @@ static MDB_meta* mdb_meta_head_r(MDB_env *env) { __asm__ __volatile__("pause"); #endif mdb_coherent_barrier(); - if (loop > 2) - pthread_yield(); - } while (++loop < 5); + loop += 1; + if(likely(loop < 3)) + continue; + if(unlikely(loop > 5)) + break; + pthread_yield(); + } rc = mdb_mutex_lock(env, MDB_MUTEX(env, w)); h = mdb_meta_head_w(env);