]>
Commit | Line | Data |
---|---|---|
b67e2c8c | 1 | |
2 | /* | |
262a0e14 | 3 | * $Id$ |
b67e2c8c | 4 | * |
5 | * DEBUG: section 77 Delay Pools | |
6 | * AUTHOR: Robert Collins <robertc@squid-cache.org> | |
7 | * Based upon original delay pools code by | |
8 | * David Luyer <david@luyer.net> | |
9 | * | |
10 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
11 | * ---------------------------------------------------------- | |
12 | * | |
13 | * Squid is the result of efforts by numerous individuals from | |
14 | * the Internet community; see the CONTRIBUTORS file for full | |
15 | * details. Many organizations have provided support for Squid's | |
16 | * development; see the SPONSORS file for full details. Squid is | |
17 | * Copyrighted (C) 2001 by the Regents of the University of | |
18 | * California; see the COPYRIGHT file for full details. Squid | |
19 | * incorporates software developed and/or copyrighted by other | |
20 | * sources; see the CREDITS file for full details. | |
21 | * | |
22 | * This program is free software; you can redistribute it and/or modify | |
23 | * it under the terms of the GNU General Public License as published by | |
24 | * the Free Software Foundation; either version 2 of the License, or | |
25 | * (at your option) any later version. | |
26ac0430 | 26 | * |
b67e2c8c | 27 | * This program is distributed in the hope that it will be useful, |
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30 | * GNU General Public License for more details. | |
26ac0430 | 31 | * |
b67e2c8c | 32 | * You should have received a copy of the GNU General Public License |
33 | * along with this program; if not, write to the Free Software | |
34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
35 | * | |
36 | * | |
37 | * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org> | |
38 | */ | |
39 | ||
f7f3304a | 40 | #include "squid.h" |
b67e2c8c | 41 | |
9a0a18de | 42 | #if USE_DELAY_POOLS |
f7f3304a | 43 | #include "squid-old.h" |
1b76e6c1 | 44 | #include "comm/Connection.h" |
b67e2c8c | 45 | #include "DelayVector.h" |
a46d2c0e | 46 | #include "CommRead.h" |
b67e2c8c | 47 | |
48 | void * | |
49 | DelayVector::operator new(size_t size) | |
50 | { | |
51 | DelayPools::MemoryUsed += sizeof (DelayVector); | |
52 | return ::operator new (size); | |
53 | } | |
54 | ||
55 | void | |
56 | DelayVector::operator delete (void *address) | |
57 | { | |
58 | DelayPools::MemoryUsed -= sizeof (DelayVector); | |
59 | ::operator delete (address); | |
60 | } | |
61 | ||
2e6c0f0f | 62 | DelayVector::DelayVector() |
63 | { | |
4610ec53 | 64 | DelayPools::registerForUpdates (this); |
2e6c0f0f | 65 | } |
66 | ||
b67e2c8c | 67 | DelayVector::~DelayVector() |
2e6c0f0f | 68 | { |
4610ec53 | 69 | DelayPools::deregisterForUpdates (this); |
2e6c0f0f | 70 | } |
b67e2c8c | 71 | |
72 | void | |
73 | DelayVector::stats(StoreEntry * sentry) | |
74 | { | |
75 | iterator pos = pools.begin(); | |
62e76326 | 76 | |
b67e2c8c | 77 | while (pos != pools.end()) { |
62e76326 | 78 | (*pos)->stats(sentry); |
79 | ++pos; | |
b67e2c8c | 80 | } |
81 | } | |
82 | ||
83 | void | |
84 | DelayVector::dump(StoreEntry *entry) const | |
85 | { | |
86 | const_iterator pos = pools.begin(); | |
62e76326 | 87 | |
b67e2c8c | 88 | while (pos != pools.end()) { |
62e76326 | 89 | (*pos)->dump(entry); |
90 | ++pos; | |
b67e2c8c | 91 | } |
92 | } | |
93 | ||
94 | void | |
95 | DelayVector::update(int incr) | |
96 | { | |
2e6c0f0f | 97 | /* |
98 | * Each pool updates itself, | |
99 | * but we may have deferred reads waiting on the pool as a whole. | |
100 | */ | |
a46d2c0e | 101 | |
102 | kickReads(); | |
b67e2c8c | 103 | } |
104 | ||
105 | void | |
106 | DelayVector::parse() | |
107 | { | |
108 | iterator pos = pools.begin(); | |
62e76326 | 109 | |
b67e2c8c | 110 | while (pos != pools.end()) { |
62e76326 | 111 | (*pos)->parse(); |
112 | ++pos; | |
b67e2c8c | 113 | } |
114 | } | |
115 | ||
116 | DelayIdComposite::Pointer | |
1e5562e3 | 117 | DelayVector::id(CompositeSelectionDetails &details) |
b67e2c8c | 118 | { |
1e5562e3 | 119 | return new Id(this, details); |
b67e2c8c | 120 | } |
121 | ||
122 | void | |
123 | DelayVector::push_back(CompositePoolNode::Pointer aNode) | |
124 | { | |
125 | pools.push_back(aNode); | |
126 | } | |
127 | ||
128 | void * | |
129 | DelayVector::Id::operator new(size_t size) | |
130 | { | |
131 | DelayPools::MemoryUsed += sizeof (Id); | |
132 | return ::operator new (size); | |
133 | } | |
134 | ||
135 | void | |
136 | DelayVector::Id::operator delete (void *address) | |
137 | { | |
138 | DelayPools::MemoryUsed -= sizeof (Id); | |
139 | ::operator delete (address); | |
140 | } | |
141 | ||
1e5562e3 | 142 | DelayVector::Id::Id(DelayVector::Pointer aDelayVector, CompositeSelectionDetails &details) : theVector(aDelayVector) |
b67e2c8c | 143 | { |
bf8fe701 | 144 | debugs(77, 3, "DelayVector::Id::Id"); |
b67e2c8c | 145 | DelayVector::iterator pos = theVector->pools.begin(); |
62e76326 | 146 | |
1e5562e3 | 147 | while (pos != theVector->pools.end()) { |
148 | ids.push_back ((*pos)->id (details)); | |
62e76326 | 149 | ++pos; |
b67e2c8c | 150 | } |
151 | } | |
152 | ||
2f44bd34 | 153 | DelayVector::Id::~Id() |
154 | { | |
bf8fe701 | 155 | debugs(77, 3, "DelayVector::Id::~Id"); |
2f44bd34 | 156 | } |
157 | ||
b67e2c8c | 158 | int |
a748a390 | 159 | DelayVector::Id::bytesWanted (int minimum, int maximum) const |
b67e2c8c | 160 | { |
a748a390 | 161 | int nbytes = maximum; |
b67e2c8c | 162 | const_iterator pos = ids.begin(); |
62e76326 | 163 | |
b67e2c8c | 164 | while (pos != ids.end()) { |
a748a390 | 165 | nbytes = min (nbytes, (*pos)->bytesWanted(minimum, nbytes)); |
62e76326 | 166 | ++pos; |
b67e2c8c | 167 | } |
62e76326 | 168 | |
a748a390 | 169 | nbytes = max(minimum, nbytes); |
b67e2c8c | 170 | return nbytes; |
171 | } | |
172 | ||
173 | void | |
174 | DelayVector::Id::bytesIn(int qty) | |
175 | { | |
176 | iterator pos = ids.begin(); | |
62e76326 | 177 | |
b67e2c8c | 178 | while (pos != ids.end()) { |
62e76326 | 179 | (*pos)->bytesIn(qty); |
180 | ++pos; | |
b67e2c8c | 181 | } |
a46d2c0e | 182 | |
183 | theVector->kickReads(); | |
184 | } | |
185 | ||
186 | void | |
187 | DelayVector::Id::delayRead(DeferredRead const &aRead) | |
188 | { | |
189 | theVector->delayRead(aRead); | |
b67e2c8c | 190 | } |
62e76326 | 191 | |
b67e2c8c | 192 | #endif |