mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 06:59:32 +03:00
fix atomic access for MADV_FREE in os_reset
This commit is contained in:
parent
ebf951e851
commit
28014ee2bc
1 changed files with 4 additions and 4 deletions
8
src/os.c
8
src/os.c
|
@ -759,12 +759,12 @@ static bool mi_os_resetx(void* addr, size_t size, bool reset, mi_stats_t* stats)
|
||||||
if (p != start) return false;
|
if (p != start) return false;
|
||||||
#else
|
#else
|
||||||
#if defined(MADV_FREE)
|
#if defined(MADV_FREE)
|
||||||
static int advice = MADV_FREE;
|
static _Atomic(uintptr_t) advice = ATOMIC_VAR_INIT(MADV_FREE);
|
||||||
int err = madvise(start, csize, advice);
|
int err = madvise(start, csize, (int)mi_atomic_read_relaxed(&advice));
|
||||||
if (err != 0 && errno == EINVAL && advice == MADV_FREE) {
|
if (err != 0 && errno == EINVAL && advice == MADV_FREE) {
|
||||||
// if MADV_FREE is not supported, fall back to MADV_DONTNEED from now on
|
// if MADV_FREE is not supported, fall back to MADV_DONTNEED from now on
|
||||||
advice = MADV_DONTNEED;
|
mi_atomic_write(&advice, MADV_DONTNEED);
|
||||||
err = madvise(start, csize, advice);
|
err = madvise(start, csize, MADV_DONTNEED);
|
||||||
}
|
}
|
||||||
#elif defined(__wasi__)
|
#elif defined(__wasi__)
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue