5 * DEBUG: section 77 Delay Pools
6 * AUTHOR: Robert Collins <robertc@squid-cache.org>
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
35 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
42 #include "DelayTagged.h"
43 #include "NullDelayId.h"
47 DelayTagged::operator new(size_t size
)
49 DelayPools::MemoryUsed
+= sizeof (DelayTagged
);
50 return ::operator new (size
);
54 DelayTagged::operator delete (void *address
)
56 DelayPools::MemoryUsed
-= sizeof (DelayTagged
);
57 ::operator delete (address
);
60 DelayTagged::DelayTagged()
62 DelayPools::registerForUpdates (this);
65 static SplayNode
<DelayTaggedBucket::Pointer
>::SPLAYFREE DelayTaggedFree
;
67 DelayTagged::~DelayTagged()
69 DelayPools::deregisterForUpdates (this);
70 buckets
.head
->destroy (DelayTaggedFree
);
73 static SplayNode
<DelayTaggedBucket::Pointer
>::SPLAYCMP DelayTaggedCmp
;
76 DelayTaggedCmp(DelayTaggedBucket::Pointer
const &left
, DelayTaggedBucket::Pointer
const &right
)
78 /* for rate limiting, case insensitive */
79 return left
->tag
.caseCmp(right
->tag
);
83 DelayTaggedFree(DelayTaggedBucket::Pointer
&)
87 DelayTaggedStatsWalkee(DelayTaggedBucket::Pointer
const ¤t
, void *state
)
89 current
->stats ((StoreEntry
*)state
);
93 DelayTagged::stats(StoreEntry
* sentry
)
95 spec
.stats (sentry
, "Per Tag");
97 if (spec
.restore_bps
== -1)
100 storeAppendPrintf(sentry
, "\t\tCurrent: ");
103 storeAppendPrintf (sentry
, "Not used yet.\n\n");
107 buckets
.head
->walk(DelayTaggedStatsWalkee
, sentry
);
108 storeAppendPrintf(sentry
, "\n\n");
112 DelayTagged::dump(StoreEntry
*entry
) const
117 struct DelayTaggedUpdater
{
118 DelayTaggedUpdater (DelaySpec
&_spec
, int _incr
):spec(_spec
),incr(_incr
) {};
125 DelayTaggedUpdateWalkee(DelayTaggedBucket::Pointer
const ¤t
, void *state
)
127 DelayTaggedUpdater
*t
= (DelayTaggedUpdater
*)state
;
128 /* This doesn't change the value of the DelayTaggedBucket, so is safe */
129 const_cast<DelayTaggedBucket
*>(current
.getRaw())->theBucket
.update(t
->spec
, t
->incr
);
133 DelayTagged::update(int incr
)
135 DelayTaggedUpdater
updater(spec
, incr
);
136 buckets
.head
->walk (DelayTaggedUpdateWalkee
, &updater
);
146 DelayIdComposite::Pointer
148 DelayTagged::id(CompositePoolNode::CompositeSelectionDetails
&details
)
150 if (!details
.tag
.size())
151 return new NullDelayId
;
153 return new Id(this, details
.tag
);
157 DelayTagged::Id::operator new(size_t size
)
159 DelayPools::MemoryUsed
+= sizeof (Id
);
160 return ::operator new (size
);
164 DelayTagged::Id::operator delete (void *address
)
166 DelayPools::MemoryUsed
-= sizeof (Id
);
167 ::operator delete (address
);
171 DelayTaggedBucket::operator new(size_t size
)
173 DelayPools::MemoryUsed
+= sizeof (DelayTaggedBucket
);
174 return ::operator new (size
);
178 DelayTaggedBucket::operator delete (void *address
)
180 DelayPools::MemoryUsed
-= sizeof (DelayTaggedBucket
);
181 ::operator delete (address
);
184 DelayTaggedBucket::DelayTaggedBucket(String
&aTag
) : tag (aTag
)
186 debugs(77, 3, "DelayTaggedBucket::DelayTaggedBucket");
189 DelayTaggedBucket::~DelayTaggedBucket()
191 debugs(77, 3, "DelayTaggedBucket::~DelayTaggedBucket");
195 DelayTaggedBucket::stats (StoreEntry
*entry
) const
197 storeAppendPrintf(entry
, " :" SQUIDSTRINGPH
, SQUIDSTRINGPRINT(tag
));
198 theBucket
.stats (entry
);
201 DelayTagged::Id::Id(DelayTagged::Pointer aDelayTagged
, String
&aTag
) : theTagged(aDelayTagged
)
203 theBucket
= new DelayTaggedBucket(aTag
);
204 DelayTaggedBucket::Pointer
const *existing
= theTagged
->buckets
.find(theBucket
, DelayTaggedCmp
);
207 theBucket
= *existing
;
211 theBucket
->theBucket
.init(theTagged
->spec
);
212 theTagged
->buckets
.head
= theTagged
->buckets
.head
->insert (theBucket
, DelayTaggedCmp
);
215 DelayTagged::Id::~Id()
217 debugs(77, 3, "DelayTagged::Id::~Id");
221 DelayTagged::Id::bytesWanted (int min
, int max
) const
223 return theBucket
->theBucket
.bytesWanted(min
,max
);
227 DelayTagged::Id::bytesIn(int qty
)
229 theBucket
->theBucket
.bytesIn(qty
);
233 DelayTagged::Id::delayRead(DeferredRead
const &aRead
)
235 theTagged
->delayRead(aRead
);