From d498a4bb08f1220c089b2c2c06c26b5ff937e30c Mon Sep 17 00:00:00 2001 From: David Goldblatt Date: Mon, 2 Mar 2020 18:14:19 -0800 Subject: [PATCH] Cache bin: Add an emptiness assertion. --- include/jemalloc/internal/cache_bin.h | 7 +++++++ src/tcache.c | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/jemalloc/internal/cache_bin.h b/include/jemalloc/internal/cache_bin.h index 461b20be..cc72af6b 100644 --- a/include/jemalloc/internal/cache_bin.h +++ b/include/jemalloc/internal/cache_bin.h @@ -146,6 +146,13 @@ cache_bin_empty_position_get(cache_bin_t *bin, cache_bin_info_t *info) { return ret; } +static inline void +cache_bin_assert_empty(cache_bin_t *bin, cache_bin_info_t *info) { + assert(cache_bin_ncached_get(bin, info) == 0); + assert(cache_bin_empty_position_get(bin, info) == bin->cur_ptr.ptr); +} + + /* Returns the numeric value of low water in [0, ncached]. */ static inline cache_bin_sz_t cache_bin_low_water_get(cache_bin_t *bin, cache_bin_info_t *info) { diff --git a/src/tcache.c b/src/tcache.c index a059ecc7..bffc04f5 100644 --- a/src/tcache.c +++ b/src/tcache.c @@ -566,9 +566,7 @@ tcache_destroy(tsd_t *tsd, tcache_t *tcache, bool tsd_tcache) { if (tsd_tcache) { /* Release the avail array for the TSD embedded auto tcache. */ cache_bin_t *bin = tcache_small_bin_get(tcache, 0); - assert(cache_bin_ncached_get(bin, &tcache_bin_info[0]) == 0); - assert(cache_bin_empty_position_get(bin, &tcache_bin_info[0]) == - bin->cur_ptr.ptr); + cache_bin_assert_empty(bin, &tcache_bin_info[0]); void *avail_array = (void *)((uintptr_t)bin->cur_ptr.ptr - tcache_bin_info[0].stack_size); idalloctm(tsd_tsdn(tsd), avail_array, NULL, NULL, true, true);