From 827734fa03eb4b55f74319a4ffaa0b00c9c2785d Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Thu, 11 May 2017 17:25:10 -0400 Subject: Tweak Makefile, asserts, comments. * Un-Wundef-ify -DUSE_TCACHE * More asserts in tcache get/put functions * Clarify redundancy in tcache structure --- malloc/Makefile | 4 +++- malloc/malloc.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/malloc/Makefile b/malloc/Makefile index dd8a43a6c7..e6ca11c76d 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -169,7 +169,9 @@ tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3 tst-malloc-usable-static-tunables-ENV = $(tst-malloc-usable-tunables-ENV) ifeq ($(experimental-malloc),yes) -CPPFLAGS-malloc.c += -DUSE_TCACHE +CPPFLAGS-malloc.c += -DUSE_TCACHE=1 +else +CPPFLAGS-malloc.c += -DUSE_TCACHE=0 endif # Uncomment this for test releases. For public releases it is too expensive. #CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1 diff --git a/malloc/malloc.c b/malloc/malloc.c index 91551ae1f2..d904db894e 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -2927,7 +2927,8 @@ typedef struct tcache_entry { /* There is one of these for each thread, which contains the per-thread cache (hence "tcache_perthread_struct"). Keeping overall size low is mildly important. Note that COUNTS and ENTRIES - are redundant, this is for performance reasons. */ + are redundant (we could have just counted the linked list each + time), this is for performance reasons. */ typedef struct tcache_perthread_struct { char counts[TCACHE_MAX_BINS]; tcache_entry *entries[TCACHE_MAX_BINS]; @@ -2955,6 +2956,7 @@ tcache_get (size_t tc_idx) { tcache_entry *e = tcache->entries[tc_idx]; assert (tc_idx < TCACHE_MAX_BINS); + assert (tcache->entries[tc_idx] > 0); tcache->entries[tc_idx] = e->next; --(tcache->counts[tc_idx]); return (void *) e; -- cgit 1.4.1