From 6f6c581c6e09240b46f6fd852fd35ff225977f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Fri, 8 Jul 2022 22:08:10 +0300 Subject: [PATCH] mdbx: minor refine `safe64_write()`, `safe64_read()` and `safe64_inc()`. --- src/core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core.c b/src/core.c index 1f63520e..9f38e65f 100644 --- a/src/core.c +++ b/src/core.c @@ -1146,7 +1146,7 @@ static __always_inline bool safe64_reset_compare(MDBX_atomic_uint64_t *p, static __always_inline void safe64_write(MDBX_atomic_uint64_t *p, const uint64_t v) { assert(p->weak >= SAFE64_INVALID_THRESHOLD); -#if MDBX_64BIT_ATOMIC +#if MDBX_64BIT_ATOMIC && MDBX_64BIT_CAS atomic_store64(p, v, mo_AcquireRelease); #else /* MDBX_64BIT_ATOMIC */ mdbx_compiler_barrier(); @@ -1163,8 +1163,10 @@ static __always_inline void safe64_write(MDBX_atomic_uint64_t *p, static __always_inline uint64_t safe64_read(const MDBX_atomic_uint64_t *p) { mdbx_jitter4testing(true); - uint64_t v = atomic_load64(p, mo_AcquireRelease); - mdbx_jitter4testing(true); + uint64_t v; + do + v = atomic_load64(p, mo_AcquireRelease); + while (!MDBX_64BIT_ATOMIC && unlikely(v != p->weak)); return v; } @@ -1206,7 +1208,7 @@ MDBX_MAYBE_UNUSED static void safe64_inc(MDBX_atomic_uint64_t *p, const uint64_t v) { assert(v > 0); - safe64_update(p, atomic_load64(p, mo_Relaxed) + v); + safe64_update(p, safe64_read(p) + v); } /*----------------------------------------------------------------------------*/