From 0dcd576600b7ad1b4a142eb993e4f7639ccc638c Mon Sep 17 00:00:00 2001 From: David Goldblatt Date: Tue, 18 Feb 2020 17:26:32 -0800 Subject: [PATCH] Edata cache: atomic fetch-add -> load-store. The modifications to count are protected by a mutex; there's no need to use the more costly version. --- src/edata_cache.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/edata_cache.c b/src/edata_cache.c index b62972a1..4601f33c 100644 --- a/src/edata_cache.c +++ b/src/edata_cache.c @@ -27,7 +27,8 @@ edata_cache_get(tsdn_t *tsdn, edata_cache_t *edata_cache) { return base_alloc_edata(tsdn, edata_cache->base); } edata_avail_remove(&edata_cache->avail, edata); - atomic_fetch_sub_zu(&edata_cache->count, 1, ATOMIC_RELAXED); + size_t count = atomic_load_zu(&edata_cache->count, ATOMIC_RELAXED); + atomic_store_zu(&edata_cache->count, count - 1, ATOMIC_RELAXED); malloc_mutex_unlock(tsdn, &edata_cache->mtx); return edata; } @@ -36,7 +37,8 @@ void edata_cache_put(tsdn_t *tsdn, edata_cache_t *edata_cache, edata_t *edata) { malloc_mutex_lock(tsdn, &edata_cache->mtx); edata_avail_insert(&edata_cache->avail, edata); - atomic_fetch_add_zu(&edata_cache->count, 1, ATOMIC_RELAXED); + size_t count = atomic_load_zu(&edata_cache->count, ATOMIC_RELAXED); + atomic_store_zu(&edata_cache->count, count + 1, ATOMIC_RELAXED); malloc_mutex_unlock(tsdn, &edata_cache->mtx); }