mirror of
https://github.com/isar/libmdbx.git
synced 2025-02-01 05:48:22 +08:00
mdbx: avoid tsan-trap in mdb_meta_head_r().
Change-Id: I594c13e1fe908f8afdc663d349cfc4cf634bba77
This commit is contained in:
parent
5bc0a76899
commit
4e5d5ef935
17
mdb.c
17
mdb.c
@ -1857,17 +1857,18 @@ static MDB_meta* mdb_meta_head_w(MDB_env *env) {
|
|||||||
return a;
|
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* a = METAPAGE_1(env);
|
||||||
MDB_meta* b = METAPAGE_2(env), *h;
|
MDB_meta* b = METAPAGE_2(env), *h;
|
||||||
txnid_t head_txnid;
|
txnid_t head_txnid;
|
||||||
int loop = 0, rc;
|
int loop = 0, rc;
|
||||||
|
|
||||||
do {
|
while(1) {
|
||||||
head_txnid = env->me_txns->mti_txnid;
|
head_txnid = env->me_txns->mti_txnid;
|
||||||
|
|
||||||
mdb_assert(env, a->mm_txnid != b->mm_txnid || head_txnid == 0);
|
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;
|
return a;
|
||||||
if (likely(b->mm_txnid == head_txnid))
|
if (likely(b->mm_txnid == head_txnid))
|
||||||
return b;
|
return b;
|
||||||
@ -1877,9 +1878,13 @@ static MDB_meta* mdb_meta_head_r(MDB_env *env) {
|
|||||||
__asm__ __volatile__("pause");
|
__asm__ __volatile__("pause");
|
||||||
#endif
|
#endif
|
||||||
mdb_coherent_barrier();
|
mdb_coherent_barrier();
|
||||||
if (loop > 2)
|
loop += 1;
|
||||||
pthread_yield();
|
if(likely(loop < 3))
|
||||||
} while (++loop < 5);
|
continue;
|
||||||
|
if(unlikely(loop > 5))
|
||||||
|
break;
|
||||||
|
pthread_yield();
|
||||||
|
}
|
||||||
|
|
||||||
rc = mdb_mutex_lock(env, MDB_MUTEX(env, w));
|
rc = mdb_mutex_lock(env, MDB_MUTEX(env, w));
|
||||||
h = mdb_meta_head_w(env);
|
h = mdb_meta_head_w(env);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user