/*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
MemChunk::MemChunk(MemPoolChunked *aPool)
{
/* should have a pool for this too -
- * note that this requres:
+ * note that this requires:
* allocate one chunk for the pool of chunks's first chunk
* allocate a chunk from that pool
* move the contents of one chunk into the other
nextFreeChunk = pool->nextFreeChunk;
pool->nextFreeChunk = this;
- memMeterAdd(pool->getMeter().alloc, pool->chunk_capacity);
- memMeterAdd(pool->getMeter().idle, pool->chunk_capacity);
+ pool->getMeter().alloc += pool->chunk_capacity;
+ pool->getMeter().idle += pool->chunk_capacity;
++pool->chunkCount;
lastref = squid_curtime;
pool->allChunks.insert(this, memCompChunks);
}
MemPoolChunked::MemPoolChunked(const char *aLabel, size_t aSize) :
- MemImplementingAllocator(aLabel, aSize) , chunk_size(0),
- chunk_capacity(0), chunkCount(0), freeCache(0), nextFreeChunk(0),
- Chunks(0), allChunks(Splay<MemChunk *>())
+ MemImplementingAllocator(aLabel, aSize), chunk_size(0),
+ chunk_capacity(0), chunkCount(0), freeCache(0), nextFreeChunk(0),
+ Chunks(0), allChunks(Splay<MemChunk *>())
{
setChunkSize(MEM_CHUNK_SIZE);
MemChunk::~MemChunk()
{
- memMeterDel(pool->getMeter().alloc, pool->chunk_capacity);
- memMeterDel(pool->getMeter().idle, pool->chunk_capacity);
+ pool->getMeter().alloc -= pool->chunk_capacity;
+ pool->getMeter().idle -= pool->chunk_capacity;
-- pool->chunkCount;
pool->allChunks.remove(this, memCompChunks);
xfree(objCache);
flushMetersFull();
clean(0);
- assert(meter.inuse.level == 0);
+ assert(meter.inuse.currentLevel() == 0);
chunk = Chunks;
while ( (fchunk = chunk) != NULL) {
int
MemPoolChunked::getInUseCount()
{
- return meter.inuse.level;
+ return meter.inuse.currentLevel();
}
void *
MemPoolChunked::allocate()
{
void *p = get();
- assert(meter.idle.level > 0);
- memMeterDec(meter.idle);
- memMeterInc(meter.inuse);
+ assert(meter.idle.currentLevel() > 0);
+ --meter.idle;
+ ++meter.inuse;
return p;
}
MemPoolChunked::deallocate(void *obj, bool)
{
push(obj);
- assert(meter.inuse.level > 0);
- memMeterDec(meter.inuse);
- memMeterInc(meter.idle);
+ assert(meter.inuse.currentLevel() > 0);
+ --meter.inuse;
+ ++meter.idle;
}
void
bool
MemPoolChunked::idleTrigger(int shift) const
{
- return meter.idle.level > (chunk_capacity << shift);
+ return meter.idle.currentLevel() > (chunk_capacity << shift);
}
/*
stats->chunks_partial += chunks_partial;
stats->chunks_free += chunks_free;
- stats->items_alloc += meter.alloc.level;
- stats->items_inuse += meter.inuse.level;
- stats->items_idle += meter.idle.level;
+ stats->items_alloc += meter.alloc.currentLevel();
+ stats->items_inuse += meter.inuse.currentLevel();
+ stats->items_idle += meter.idle.currentLevel();
stats->overhead += sizeof(MemPoolChunked) + chunkCount * sizeof(MemChunk) + strlen(objectType()) + 1;
- return meter.inuse.level;
+ return meter.inuse.currentLevel();
}