diff options
Diffstat (limited to 'src/pkg/runtime/mcache.c')
-rw-r--r-- | src/pkg/runtime/mcache.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/pkg/runtime/mcache.c b/src/pkg/runtime/mcache.c index 202936f6e..0f41a0ebc 100644 --- a/src/pkg/runtime/mcache.c +++ b/src/pkg/runtime/mcache.c @@ -10,7 +10,7 @@ #include "malloc.h" void* -MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed) +runtime·MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed) { MCacheList *l; MLink *first, *v; @@ -20,8 +20,8 @@ MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed) l = &c->list[sizeclass]; if(l->list == nil) { // Replenish using central lists. - n = MCentral_AllocList(&mheap.central[sizeclass], - class_to_transfercount[sizeclass], &first); + n = runtime·MCentral_AllocList(&runtime·mheap.central[sizeclass], + runtime·class_to_transfercount[sizeclass], &first); l->list = first; l->nlist = n; c->size += n*size; @@ -39,7 +39,7 @@ MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed) if(zeroed) { // block is zeroed iff second word is zero ... if(size > sizeof(uintptr) && ((uintptr*)v)[1] != 0) - runtime_memclr((byte*)v, size); + runtime·memclr((byte*)v, size); else { // ... except for the link pointer // that we used above; zero that. @@ -47,6 +47,7 @@ MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed) } } c->local_alloc += size; + c->local_objects++; return v; } @@ -67,14 +68,14 @@ ReleaseN(MCache *c, MCacheList *l, int32 n, int32 sizeclass) l->nlist -= n; if(l->nlist < l->nlistmin) l->nlistmin = l->nlist; - c->size -= n*class_to_size[sizeclass]; + c->size -= n*runtime·class_to_size[sizeclass]; // Return them to central free list. - MCentral_FreeList(&mheap.central[sizeclass], n, first); + runtime·MCentral_FreeList(&runtime·mheap.central[sizeclass], n, first); } void -MCache_Free(MCache *c, void *v, int32 sizeclass, uintptr size) +runtime·MCache_Free(MCache *c, void *v, int32 sizeclass, uintptr size) { int32 i, n; MCacheList *l; @@ -88,10 +89,11 @@ MCache_Free(MCache *c, void *v, int32 sizeclass, uintptr size) l->nlist++; c->size += size; c->local_alloc -= size; + c->local_objects--; if(l->nlist >= MaxMCacheListLen) { // Release a chunk back. - ReleaseN(c, l, class_to_transfercount[sizeclass], sizeclass); + ReleaseN(c, l, runtime·class_to_transfercount[sizeclass], sizeclass); } if(c->size >= MaxMCacheSize) { @@ -116,16 +118,11 @@ MCache_Free(MCache *c, void *v, int32 sizeclass, uintptr size) } void -MCache_ReleaseAll(MCache *c) +runtime·MCache_ReleaseAll(MCache *c) { int32 i; MCacheList *l; - lock(&mheap); - mstats.heap_alloc += c->local_alloc; - c->local_alloc = 0; - unlock(&mheap); - for(i=0; i<NumSizeClasses; i++) { l = &c->list[i]; ReleaseN(c, l, l->nlist, i); |