]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/mem/PoolChunked.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / mem / PoolChunked.cc
index cee007256fe5b1c5eb247bc49509da8a53ad99f0..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,23 +128,18 @@ 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)
+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 *>())
 {
-    chunk_size = 0;
-    chunk_capacity = 0;
-    chunkCount = 0;
-    freeCache = 0;
-    nextFreeChunk = 0;
-    Chunks = 0;
-    next = 0;
-
     setChunkSize(MEM_CHUNK_SIZE);
 
 #if HAVE_MALLOPT && M_MMAP_MAX
@@ -154,8 +149,8 @@ MemPoolChunked::MemPoolChunked(const char *aLabel, size_t aSize) : MemImplementi
 
 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);
@@ -231,7 +226,7 @@ MemPoolChunked::createChunk()
     newChunk = new MemChunk(this);
 
     chunk = Chunks;
-    if (chunk == NULL) {       /* first chunk in pool */
+    if (chunk == NULL) {    /* first chunk in pool */
         Chunks = newChunk;
         return;
     }
@@ -260,10 +255,10 @@ MemPoolChunked::setChunkSize(size_t chunksize)
     int cap;
     size_t csize = chunksize;
 
-    if (Chunks)                /* unsafe to tamper */
+    if (Chunks)     /* unsafe to tamper */
         return;
 
-    csize = ((csize + MEM_PAGE_SIZE - 1) / MEM_PAGE_SIZE) * MEM_PAGE_SIZE;     /* round up to page size */
+    csize = ((csize + MEM_PAGE_SIZE - 1) / MEM_PAGE_SIZE) * MEM_PAGE_SIZE;  /* round up to page size */
     cap = csize / obj_size;
 
     if (cap < MEM_MIN_FREE)
@@ -276,7 +271,7 @@ MemPoolChunked::setChunkSize(size_t chunksize)
         cap = 1;
 
     csize = cap * obj_size;
-    csize = ((csize + MEM_PAGE_SIZE - 1) / MEM_PAGE_SIZE) * MEM_PAGE_SIZE;     /* round up to page size */
+    csize = ((csize + MEM_PAGE_SIZE - 1) / MEM_PAGE_SIZE) * MEM_PAGE_SIZE;  /* round up to page size */
     cap = csize / obj_size;
 
     chunk_capacity = cap;
@@ -293,7 +288,7 @@ MemPoolChunked::~MemPoolChunked()
 
     flushMetersFull();
     clean(0);
-    assert(meter.inuse.level == 0);
+    assert(meter.inuse.currentLevel() == 0);
 
     chunk = Chunks;
     while ( (fchunk = chunk) != NULL) {
@@ -307,26 +302,26 @@ 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;
 }
 
 void
-MemPoolChunked::deallocate(void *obj, bool aggressive)
+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
@@ -345,8 +340,8 @@ MemPoolChunked::convertFreeCacheToChunkFreeCache()
         assert(chunk->inuse_count > 0);
         -- chunk->inuse_count;
         (void) VALGRIND_MAKE_MEM_DEFINED(Free, sizeof(void *));
-        freeCache = *(void **)Free;    /* remove from global cache */
-        *(void **)Free = chunk->freeList;      /* stuff into chunks freelist */
+        freeCache = *(void **)Free; /* remove from global cache */
+        *(void **)Free = chunk->freeList;   /* stuff into chunks freelist */
         (void) VALGRIND_MAKE_MEM_NOACCESS(Free, sizeof(void *));
         chunk->freeList = Free;
         chunk->lastref = squid_curtime;
@@ -422,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);
 }
 
 /*
@@ -435,10 +430,10 @@ MemPoolChunked::getStats(MemPoolStats * stats, int accumulate)
     int chunks_free = 0;
     int chunks_partial = 0;
 
-    if (!accumulate)   /* need skip memset for GlobalStats accumulation */
+    if (!accumulate)    /* need skip memset for GlobalStats accumulation */
         memset(stats, 0, sizeof(MemPoolStats));
 
-    clean((time_t) 555555);    /* don't want to get chunks released before reporting */
+    clean((time_t) 555555); /* don't want to get chunks released before reporting */
 
     stats->pool = this;
     stats->label = objectType();
@@ -461,11 +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();
 }
+