mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 05:38:20 +08:00
mdbx: minor refine safe64_write()
, safe64_read()
and safe64_inc()
.
This commit is contained in:
parent
baea4c81c9
commit
6f6c581c6e
10
src/core.c
10
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,
|
static __always_inline void safe64_write(MDBX_atomic_uint64_t *p,
|
||||||
const uint64_t v) {
|
const uint64_t v) {
|
||||||
assert(p->weak >= SAFE64_INVALID_THRESHOLD);
|
assert(p->weak >= SAFE64_INVALID_THRESHOLD);
|
||||||
#if MDBX_64BIT_ATOMIC
|
#if MDBX_64BIT_ATOMIC && MDBX_64BIT_CAS
|
||||||
atomic_store64(p, v, mo_AcquireRelease);
|
atomic_store64(p, v, mo_AcquireRelease);
|
||||||
#else /* MDBX_64BIT_ATOMIC */
|
#else /* MDBX_64BIT_ATOMIC */
|
||||||
mdbx_compiler_barrier();
|
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) {
|
static __always_inline uint64_t safe64_read(const MDBX_atomic_uint64_t *p) {
|
||||||
mdbx_jitter4testing(true);
|
mdbx_jitter4testing(true);
|
||||||
uint64_t v = atomic_load64(p, mo_AcquireRelease);
|
uint64_t v;
|
||||||
mdbx_jitter4testing(true);
|
do
|
||||||
|
v = atomic_load64(p, mo_AcquireRelease);
|
||||||
|
while (!MDBX_64BIT_ATOMIC && unlikely(v != p->weak));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1206,7 +1208,7 @@ MDBX_MAYBE_UNUSED static
|
|||||||
void
|
void
|
||||||
safe64_inc(MDBX_atomic_uint64_t *p, const uint64_t v) {
|
safe64_inc(MDBX_atomic_uint64_t *p, const uint64_t v) {
|
||||||
assert(v > 0);
|
assert(v > 0);
|
||||||
safe64_update(p, atomic_load64(p, mo_Relaxed) + v);
|
safe64_update(p, safe64_read(p) + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user