]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/mem/PoolChunked.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / mem / PoolChunked.cc
index abbd17ddd00b3f93f1a7059aaea54295152db5f0..812cbfa5799f66120dabd15a3ab9bb7334186f5c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -101,7 +101,7 @@ memCompObjChunks(void *const &obj, MemChunk * const &chunk)
 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
@@ -128,17 +128,17 @@ MemChunk::MemChunk(MemPoolChunked *aPool)
     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);
 
@@ -149,8 +149,8 @@ MemPoolChunked::MemPoolChunked(const char *aLabel, size_t aSize) :
 
 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);
@@ -288,7 +288,7 @@ MemPoolChunked::~MemPoolChunked()
 
     flushMetersFull();
     clean(0);
-    assert(meter.inuse.level == 0);
+    assert(meter.inuse.currentLevel() == 0);
 
     chunk = Chunks;
     while ( (fchunk = chunk) != NULL) {
@@ -302,16 +302,16 @@ MemPoolChunked::~MemPoolChunked()
 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;
 }
 
@@ -319,9 +319,9 @@ void
 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
@@ -417,7 +417,7 @@ MemPoolChunked::clean(time_t maxage)
 bool
 MemPoolChunked::idleTrigger(int shift) const
 {
-    return meter.idle.level > (chunk_capacity << shift);
+    return meter.idle.currentLevel() > (chunk_capacity << shift);
 }
 
 /*
@@ -456,12 +456,12 @@ MemPoolChunked::getStats(MemPoolStats * stats, int accumulate)
     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();
 }