3 * DEBUG: section 77 Delay Pools
4 * AUTHOR: Robert Collins <robertc@squid-cache.org>
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
39 #include "comm/Connection.h"
40 #include "DelayTagged.h"
41 #include "NullDelayId.h"
45 DelayTagged::operator new(size_t size
)
47 DelayPools::MemoryUsed
+= sizeof (DelayTagged
);
48 return ::operator new (size
);
52 DelayTagged::operator delete (void *address
)
54 DelayPools::MemoryUsed
-= sizeof (DelayTagged
);
55 ::operator delete (address
);
58 DelayTagged::DelayTagged()
60 DelayPools::registerForUpdates (this);
63 static SplayNode
<DelayTaggedBucket::Pointer
>::SPLAYFREE DelayTaggedFree
;
65 DelayTagged::~DelayTagged()
67 DelayPools::deregisterForUpdates (this);
68 buckets
.head
->destroy (DelayTaggedFree
);
71 static SplayNode
<DelayTaggedBucket::Pointer
>::SPLAYCMP DelayTaggedCmp
;
74 DelayTaggedCmp(DelayTaggedBucket::Pointer
const &left
, DelayTaggedBucket::Pointer
const &right
)
76 /* for rate limiting, case insensitive */
77 return left
->tag
.caseCmp(right
->tag
);
81 DelayTaggedFree(DelayTaggedBucket::Pointer
&)
85 DelayTaggedStatsWalkee(DelayTaggedBucket::Pointer
const ¤t
, void *state
)
87 current
->stats ((StoreEntry
*)state
);
91 DelayTagged::stats(StoreEntry
* sentry
)
93 spec
.stats (sentry
, "Per Tag");
95 if (spec
.restore_bps
== -1)
98 storeAppendPrintf(sentry
, "\t\tCurrent: ");
101 storeAppendPrintf (sentry
, "Not used yet.\n\n");
105 buckets
.head
->walk(DelayTaggedStatsWalkee
, sentry
);
106 storeAppendPrintf(sentry
, "\n\n");
110 DelayTagged::dump(StoreEntry
*entry
) const
115 struct DelayTaggedUpdater
{
116 DelayTaggedUpdater (DelaySpec
&_spec
, int _incr
):spec(_spec
),incr(_incr
) {};
123 DelayTaggedUpdateWalkee(DelayTaggedBucket::Pointer
const ¤t
, void *state
)
125 DelayTaggedUpdater
*t
= (DelayTaggedUpdater
*)state
;
126 /* This doesn't change the value of the DelayTaggedBucket, so is safe */
127 const_cast<DelayTaggedBucket
*>(current
.getRaw())->theBucket
.update(t
->spec
, t
->incr
);
131 DelayTagged::update(int incr
)
133 DelayTaggedUpdater
updater(spec
, incr
);
134 buckets
.head
->walk (DelayTaggedUpdateWalkee
, &updater
);
144 DelayIdComposite::Pointer
146 DelayTagged::id(CompositePoolNode::CompositeSelectionDetails
&details
)
148 if (!details
.tag
.size())
149 return new NullDelayId
;
151 return new Id(this, details
.tag
);
155 DelayTagged::Id::operator new(size_t size
)
157 DelayPools::MemoryUsed
+= sizeof (Id
);
158 return ::operator new (size
);
162 DelayTagged::Id::operator delete (void *address
)
164 DelayPools::MemoryUsed
-= sizeof (Id
);
165 ::operator delete (address
);
169 DelayTaggedBucket::operator new(size_t size
)
171 DelayPools::MemoryUsed
+= sizeof (DelayTaggedBucket
);
172 return ::operator new (size
);
176 DelayTaggedBucket::operator delete (void *address
)
178 DelayPools::MemoryUsed
-= sizeof (DelayTaggedBucket
);
179 ::operator delete (address
);
182 DelayTaggedBucket::DelayTaggedBucket(String
&aTag
) : tag (aTag
)
184 debugs(77, 3, "DelayTaggedBucket::DelayTaggedBucket");
187 DelayTaggedBucket::~DelayTaggedBucket()
189 debugs(77, 3, "DelayTaggedBucket::~DelayTaggedBucket");
193 DelayTaggedBucket::stats(StoreEntry
*entry
) const
195 storeAppendPrintf(entry
, " " SQUIDSTRINGPH
":", SQUIDSTRINGPRINT(tag
));
196 theBucket
.stats(entry
);
199 DelayTagged::Id::Id(DelayTagged::Pointer aDelayTagged
, String
&aTag
) : theTagged(aDelayTagged
)
201 theBucket
= new DelayTaggedBucket(aTag
);
202 DelayTaggedBucket::Pointer
const *existing
= theTagged
->buckets
.find(theBucket
, DelayTaggedCmp
);
205 theBucket
= *existing
;
209 theBucket
->theBucket
.init(theTagged
->spec
);
210 theTagged
->buckets
.head
= theTagged
->buckets
.head
->insert (theBucket
, DelayTaggedCmp
);
213 DelayTagged::Id::~Id()
215 debugs(77, 3, "DelayTagged::Id::~Id");
219 DelayTagged::Id::bytesWanted (int min
, int max
) const
221 return theBucket
->theBucket
.bytesWanted(min
,max
);
225 DelayTagged::Id::bytesIn(int qty
)
227 theBucket
->theBucket
.bytesIn(qty
);
231 DelayTagged::Id::delayRead(DeferredRead
const &aRead
)
233 theTagged
->delayRead(aRead
);