]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/DelayTagged.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / DelayTagged.cc
index a5c08e6041947d3627e8629d97fb64171c1bd7da..a92900d866c119a7e0a1f8bd6313155e7c784890 100644 (file)
@@ -1,94 +1,54 @@
-
 /*
- * $Id$
- *
- * DEBUG: section 77    Delay Pools
- * AUTHOR: Robert Collins <robertc@squid-cache.org>
- *
- * 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.
+ * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
  *
- *  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.
- *
- *
- * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
-#include "config.h"
+/* DEBUG: section 77    Delay Pools */
 
-#if DELAY_POOLS
 #include "squid.h"
+
+#if USE_DELAY_POOLS
+#include "comm/Connection.h"
 #include "DelayTagged.h"
-#include "authenticate.h"
 #include "NullDelayId.h"
 #include "Store.h"
 
-void *
-DelayTagged::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (DelayTagged);
-    return ::operator new (size);
-}
-
-void
-DelayTagged::operator delete (void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (DelayTagged);
-    ::operator delete (address);
-}
-
 DelayTagged::DelayTagged()
 {
     DelayPools::registerForUpdates (this);
 }
 
-static SplayNode<DelayTaggedBucket::Pointer>::SPLAYFREE DelayTaggedFree;
+static Splay<DelayTaggedBucket::Pointer>::SPLAYFREE DelayTaggedFree;
 
 DelayTagged::~DelayTagged()
 {
     DelayPools::deregisterForUpdates (this);
-    buckets.head->destroy (DelayTaggedFree);
+    buckets.destroy(DelayTaggedFree);
 }
 
-static SplayNode<DelayTaggedBucket::Pointer>::SPLAYCMP DelayTaggedCmp;
+static Splay<DelayTaggedBucket::Pointer>::SPLAYCMP DelayTaggedCmp;
 
 int
 DelayTaggedCmp(DelayTaggedBucket::Pointer const &left, DelayTaggedBucket::Pointer const &right)
 {
     /* for rate limiting, case insensitive */
-    return left->tag.caseCmp(right->tag.unsafeBuf());
+    return left->tag.caseCmp(right->tag);
 }
 
 void
 DelayTaggedFree(DelayTaggedBucket::Pointer &)
 {}
 
-void
-DelayTaggedStatsWalkee(DelayTaggedBucket::Pointer const &current, void *state)
-{
-    current->stats ((StoreEntry *)state);
-}
+struct DelayTaggedStatsVisitor {
+    StoreEntry *sentry;
+    explicit DelayTaggedStatsVisitor(StoreEntry *se): sentry(se) {}
+    void operator() (DelayTaggedBucket::Pointer const &current) {
+        current->stats(sentry);
+    }
+};
 
 void
 DelayTagged::stats(StoreEntry * sentry)
@@ -100,12 +60,13 @@ DelayTagged::stats(StoreEntry * sentry)
 
     storeAppendPrintf(sentry, "\t\tCurrent: ");
 
-    if (!buckets.head) {
+    if (buckets.empty()) {
         storeAppendPrintf (sentry, "Not used yet.\n\n");
         return;
     }
 
-    buckets.head->walk(DelayTaggedStatsWalkee, sentry);
+    DelayTaggedStatsVisitor visitor(sentry);
+    buckets.visit(visitor);
     storeAppendPrintf(sentry, "\n\n");
 }
 
@@ -130,11 +91,20 @@ DelayTaggedUpdateWalkee(DelayTaggedBucket::Pointer const &current, void *state)
     const_cast<DelayTaggedBucket *>(current.getRaw())->theBucket.update(t->spec, t->incr);
 }
 
+struct DelayTaggedUpdateVisitor {
+    DelayTaggedUpdater *updater;
+    explicit DelayTaggedUpdateVisitor(DelayTaggedUpdater *u) : updater(u) {}
+    void operator() (DelayTaggedBucket::Pointer const &current) {
+        const_cast<DelayTaggedBucket *>(current.getRaw())->theBucket.update(updater->spec, updater->incr);
+    }
+};
+
 void
 DelayTagged::update(int incr)
 {
     DelayTaggedUpdater updater(spec, incr);
-    buckets.head->walk (DelayTaggedUpdateWalkee, &updater);
+    DelayTaggedUpdateVisitor visitor(&updater);
+    buckets.visit(visitor);
     kickReads();
 }
 
@@ -154,34 +124,6 @@ DelayTagged::id(CompositePoolNode::CompositeSelectionDetails &details)
     return new Id(this, details.tag);
 }
 
-void *
-DelayTagged::Id::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (Id);
-    return ::operator new (size);
-}
-
-void
-DelayTagged::Id::operator delete (void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (Id);
-    ::operator delete (address);
-}
-
-void *
-DelayTaggedBucket::operator new(size_t size)
-{
-    DelayPools::MemoryUsed += sizeof (DelayTaggedBucket);
-    return ::operator new (size);
-}
-
-void
-DelayTaggedBucket::operator delete (void *address)
-{
-    DelayPools::MemoryUsed -= sizeof (DelayTaggedBucket);
-    ::operator delete (address);
-}
-
 DelayTaggedBucket::DelayTaggedBucket(String &aTag) : tag (aTag)
 {
     debugs(77, 3, "DelayTaggedBucket::DelayTaggedBucket");
@@ -193,10 +135,10 @@ DelayTaggedBucket::~DelayTaggedBucket()
 }
 
 void
-DelayTaggedBucket::stats (StoreEntry *entry) const
+DelayTaggedBucket::stats(StoreEntry *entry) const
 {
-    storeAppendPrintf(entry, " %s:", tag.unsafeBuf());
-    theBucket.stats (entry);
+    storeAppendPrintf(entry, " " SQUIDSTRINGPH ":", SQUIDSTRINGPRINT(tag));
+    theBucket.stats(entry);
 }
 
 DelayTagged::Id::Id(DelayTagged::Pointer aDelayTagged, String &aTag) : theTagged(aDelayTagged)
@@ -210,7 +152,7 @@ DelayTagged::Id::Id(DelayTagged::Pointer aDelayTagged, String &aTag) : theTagged
     }
 
     theBucket->theBucket.init(theTagged->spec);
-    theTagged->buckets.head = theTagged->buckets.head->insert (theBucket, DelayTaggedCmp);
+    theTagged->buckets.insert (theBucket, DelayTaggedCmp);
 }
 
 DelayTagged::Id::~Id()
@@ -237,3 +179,4 @@ DelayTagged::Id::delayRead(DeferredRead const &aRead)
 }
 
 #endif
+