]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/repl/heap/store_repl_heap.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / repl / heap / store_repl_heap.cc
index 270f780f1cefc4bf2e0ed5fd8d230ff0eda7c53c..524fc9c8b261164517c66d273d1573d89e98afdc 100644 (file)
@@ -1,7 +1,13 @@
+/*
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
 
 /*
  * DEBUG: section 81    Store HEAP Removal Policies
- * AUTHOR: Henrik Nordstrom
  *
  * Based on the ideas of the heap policy implemented by John Dilley of
  * Hewlett Packard. Rewritten from scratch when modularizing the removal
  *
  * For details on the original heap policy work and the thinking behind see
  * http://www.hpl.hp.com/techreports/1999/HPL-1999-69.html
- *
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
  */
 
 #include "squid.h"
 #include "heap.h"
 #include "MemObject.h"
-#include "SquidList.h"
 #include "Store.h"
 #include "store_heap_replacement.h"
 #include "wordlist.h"
 
+#include <queue>
+
 REMOVALPOLICYCREATE createRemovalPolicy_heap;
 
 static int nr_heap_policies = 0;
@@ -105,7 +84,7 @@ heap_add(RemovalPolicy * policy, StoreEntry * entry, RemovalPolicyNode * node)
     assert(!node->data);
 
     if (EBIT_TEST(entry->flags, ENTRY_SPECIAL))
-        return;                        /* We won't manage these.. they messes things up */
+        return;         /* We won't manage these.. they messes things up */
 
     node->data = heap_insert(h->theHeap, entry);
 
@@ -165,7 +144,7 @@ heap_walkNext(RemovalPolicyWalker * walker)
     StoreEntry *entry;
 
     if (heap_walk->current >= heap_nodes(h->theHeap))
-        return NULL;           /* done */
+        return NULL;        /* done */
 
     entry = (StoreEntry *) heap_peep(h->theHeap, heap_walk->current++);
 
@@ -203,11 +182,11 @@ heap_walkInit(RemovalPolicy * policy)
 
 /** RemovalPurgeWalker **/
 
-typedef struct _HeapPurgeData HeapPurgeData;
-
-struct _HeapPurgeData {
-    link_list *locked_entries;
-    heap_key min_age;
+class HeapPurgeData
+{
+public:
+    std::queue<StoreEntry *> locked_entries;
+    heap_key min_age = 0.0;
 };
 
 static StoreEntry *
@@ -221,8 +200,8 @@ heap_purgeNext(RemovalPurgeWalker * walker)
 
 try_again:
 
-    if (!heap_nodes(h->theHeap) > 0)
-        return NULL;           /* done */
+    if (heap_empty(h->theHeap))
+        return NULL;        /* done */
 
     age = heap_peepminkey(h->theHeap);
 
@@ -231,7 +210,7 @@ try_again:
     if (entry->locked()) {
 
         entry->lock("heap_purgeNext");
-        linklistPush(&heap_walker->locked_entries, entry);
+        heap_walker->locked_entries.push(entry);
 
         goto try_again;
     }
@@ -247,7 +226,6 @@ heap_purgeDone(RemovalPurgeWalker * walker)
     HeapPurgeData *heap_walker = (HeapPurgeData *)walker->_data;
     RemovalPolicy *policy = walker->_policy;
     HeapPolicyData *h = (HeapPolicyData *)policy->_data;
-    StoreEntry *entry;
     assert(strcmp(policy->_type, "heap") == 0);
     assert(h->nwalkers > 0);
     h->nwalkers -= 1;
@@ -257,16 +235,16 @@ heap_purgeDone(RemovalPurgeWalker * walker)
         debugs(81, 3, "Heap age set to " << h->theHeap->age);
     }
 
-    /*
-     * Reinsert the locked entries
-     */
-    while ((entry = (StoreEntry *)linklistShift(&heap_walker->locked_entries))) {
+    // Reinsert the locked entries
+    while (!heap_walker->locked_entries.empty()) {
+        StoreEntry *entry = heap_walker->locked_entries.front();
         heap_node *node = heap_insert(h->theHeap, entry);
         h->setPolicyNode(entry, node);
         entry->unlock("heap_purgeDone");
+        heap_walker->locked_entries.pop();
     }
 
-    safe_free(walker->_data);
+    delete heap_walker;
     delete walker;
 }
 
@@ -278,9 +256,7 @@ heap_purgeInit(RemovalPolicy * policy, int max_scan)
     HeapPurgeData *heap_walk;
     h->nwalkers += 1;
     walker = new RemovalPurgeWalker;
-    heap_walk = (HeapPurgeData *)xcalloc(1, sizeof(*heap_walk));
-    heap_walk->min_age = 0.0;
-    heap_walk->locked_entries = NULL;
+    heap_walk = new HeapPurgeData;
     walker->_policy = policy;
     walker->_data = heap_walk;
     walker->max_scan = max_scan;
@@ -368,3 +344,4 @@ createRemovalPolicy_heap(wordlist * args)
 
     return policy;
 }
+