mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:14:12 +08:00
mdbx: refine bind_rslot()
.
This commit is contained in:
parent
a4a35ce9cb
commit
434ad8edc8
16
src/core.c
16
src/core.c
@ -7767,10 +7767,10 @@ static bind_rslot_result bind_rslot(MDBX_env *env, const uintptr_t tid) {
|
|||||||
result.err = MDBX_SUCCESS;
|
result.err = MDBX_SUCCESS;
|
||||||
unsigned slot, nreaders;
|
unsigned slot, nreaders;
|
||||||
while (1) {
|
while (1) {
|
||||||
nreaders = atomic_load32(&env->me_lck->mti_numreaders, mo_Relaxed);
|
nreaders = env->me_lck->mti_numreaders.weak;
|
||||||
for (slot = 0; slot < nreaders; slot++)
|
for (slot = 0; slot < nreaders; slot++)
|
||||||
if (atomic_load32(&env->me_lck->mti_readers[slot].mr_pid, mo_Relaxed) ==
|
if (!atomic_load32(&env->me_lck->mti_readers[slot].mr_pid,
|
||||||
0)
|
mo_AcquireRelease))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (likely(slot < env->me_maxreaders))
|
if (likely(slot < env->me_maxreaders))
|
||||||
@ -7791,13 +7791,12 @@ static bind_rslot_result bind_rslot(MDBX_env *env, const uintptr_t tid) {
|
|||||||
* slot, next publish it in lck->mti_numreaders. After
|
* slot, next publish it in lck->mti_numreaders. After
|
||||||
* that, it is safe for mdbx_env_close() to touch it.
|
* that, it is safe for mdbx_env_close() to touch it.
|
||||||
* When it will be closed, we can finally claim it. */
|
* When it will be closed, we can finally claim it. */
|
||||||
atomic_store32(&result.rslot->mr_pid, 0, mo_Relaxed);
|
atomic_store32(&result.rslot->mr_pid, 0, mo_SequentialConsistency);
|
||||||
safe64_reset(&result.rslot->mr_txnid, true);
|
safe64_reset(&result.rslot->mr_txnid, true);
|
||||||
if (slot == nreaders)
|
if (slot == nreaders)
|
||||||
atomic_store32(&env->me_lck->mti_numreaders, ++nreaders, mo_Relaxed);
|
env->me_lck->mti_numreaders.weak = ++nreaders;
|
||||||
atomic_store64(&result.rslot->mr_tid, (env->me_flags & MDBX_NOTLS) ? 0 : tid,
|
result.rslot->mr_tid.weak = (env->me_flags & MDBX_NOTLS) ? 0 : tid;
|
||||||
mo_Relaxed);
|
atomic_store32(&result.rslot->mr_pid, env->me_pid, mo_AcquireRelease);
|
||||||
atomic_store32(&result.rslot->mr_pid, env->me_pid, mo_Relaxed);
|
|
||||||
mdbx_rdt_unlock(env);
|
mdbx_rdt_unlock(env);
|
||||||
|
|
||||||
if (likely(env->me_flags & MDBX_ENV_TXKEY)) {
|
if (likely(env->me_flags & MDBX_ENV_TXKEY)) {
|
||||||
@ -7862,6 +7861,7 @@ __cold int mdbx_thread_unregister(const MDBX_env *env) {
|
|||||||
r->mr_tid.weak != mdbx_thread_self()))
|
r->mr_tid.weak != mdbx_thread_self()))
|
||||||
return MDBX_BAD_RSLOT;
|
return MDBX_BAD_RSLOT;
|
||||||
|
|
||||||
|
mdbx_assert(env, r->mr_txnid.weak >= SAFE64_INVALID_THRESHOLD);
|
||||||
if (unlikely(r->mr_txnid.weak < SAFE64_INVALID_THRESHOLD))
|
if (unlikely(r->mr_txnid.weak < SAFE64_INVALID_THRESHOLD))
|
||||||
return MDBX_BUSY /* transaction is still active */;
|
return MDBX_BUSY /* transaction is still active */;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user