diff --git a/src/mem/mem.c b/src/mem/mem.c index 6ea39e01e..195c0a2d0 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -174,8 +174,7 @@ void *mem_alloc(size_t size, mem_destroy_h *dh) list_append(&meml, &m->le, m); mem_unlock(); #endif - - re_atomic_store(&m->nrefs, 1u, re_memory_order_relaxed); + re_atomic_weak_set(&m->nrefs, 1u); m->dh = dh; STAT_ALLOC(m, size); @@ -230,7 +229,7 @@ void *mem_realloc(void *data, size_t size) MAGIC_CHECK(m); - if (re_atomic_load(&m->nrefs, re_memory_order_acquire) > 1u) { + if (re_atomic_strong(&m->nrefs) > 1u) { void* p = mem_alloc(size, m->dh); if (p) { memcpy(p, data, m->size); @@ -378,7 +377,7 @@ void *mem_deref(void *data) m->dh(data); /* NOTE: check if the destructor called mem_ref() */ - if (re_atomic_load(&m->nrefs, re_memory_order_relaxed) > 0u) + if (re_atomic_weak(&m->nrefs) > 0u) return NULL; #if MEM_DEBUG @@ -413,7 +412,7 @@ uint32_t mem_nrefs(const void *data) MAGIC_CHECK(m); - return (uint32_t)re_atomic_load(&m->nrefs, re_memory_order_acquire); + return (uint32_t)re_atomic_strong(&m->nrefs); } @@ -427,7 +426,7 @@ static bool debug_handler(struct le *le, void *arg) (void)arg; (void)re_fprintf(stderr, " %p: nrefs=%-2u", p, - (uint32_t)re_atomic_load(&m->nrefs, re_memory_order_relaxed)); + (uint32_t)re_atomic_weak(&m->nrefs)); (void)re_fprintf(stderr, " size=%-7u", m->size);