]>
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 | ||
40 | #include "config.h" | |
41 | ||
42 | #if DELAY_POOLS | |
43 | #include "squid.h" | |
44 | #include "DelayVector.h" | |
a46d2c0e | 45 | #include "CommRead.h" |
b67e2c8c | 46 | |
47 | void * | |
48 | DelayVector::operator new(size_t size) | |
49 | { | |
50 | DelayPools::MemoryUsed += sizeof (DelayVector); | |
51 | return ::operator new (size); | |
52 | } | |
53 | ||
54 | void | |
55 | DelayVector::operator delete (void *address) | |
56 | { | |
57 | DelayPools::MemoryUsed -= sizeof (DelayVector); | |
58 | ::operator delete (address); | |
59 | } | |
60 | ||
2e6c0f0f | 61 | DelayVector::DelayVector() |
62 | { | |
4610ec53 | 63 | DelayPools::registerForUpdates (this); |
2e6c0f0f | 64 | } |
65 | ||
b67e2c8c | 66 | DelayVector::~DelayVector() |
2e6c0f0f | 67 | { |
4610ec53 | 68 | DelayPools::deregisterForUpdates (this); |
2e6c0f0f | 69 | } |
b67e2c8c | 70 | |
71 | void | |
72 | DelayVector::stats(StoreEntry * sentry) | |
73 | { | |
74 | iterator pos = pools.begin(); | |
62e76326 | 75 | |
b67e2c8c | 76 | while (pos != pools.end()) { |
62e76326 | 77 | (*pos)->stats(sentry); |
78 | ++pos; | |
b67e2c8c | 79 | } |
80 | } | |
81 | ||
82 | void | |
83 | DelayVector::dump(StoreEntry *entry) const | |
84 | { | |
85 | const_iterator pos = pools.begin(); | |
62e76326 | 86 | |
b67e2c8c | 87 | while (pos != pools.end()) { |
62e76326 | 88 | (*pos)->dump(entry); |
89 | ++pos; | |
b67e2c8c | 90 | } |
91 | } | |
92 | ||
93 | void | |
94 | DelayVector::update(int incr) | |
95 | { | |
2e6c0f0f | 96 | /* |
97 | * Each pool updates itself, | |
98 | * but we may have deferred reads waiting on the pool as a whole. | |
99 | */ | |
a46d2c0e | 100 | |
101 | kickReads(); | |
b67e2c8c | 102 | } |
103 | ||
104 | void | |
105 | DelayVector::parse() | |
106 | { | |
107 | iterator pos = pools.begin(); | |
62e76326 | 108 | |
b67e2c8c | 109 | while (pos != pools.end()) { |
62e76326 | 110 | (*pos)->parse(); |
111 | ++pos; | |
b67e2c8c | 112 | } |
113 | } | |
114 | ||
115 | DelayIdComposite::Pointer | |
1e5562e3 | 116 | DelayVector::id(CompositeSelectionDetails &details) |
b67e2c8c | 117 | { |
1e5562e3 | 118 | return new Id(this, details); |
b67e2c8c | 119 | } |
120 | ||
121 | void | |
122 | DelayVector::push_back(CompositePoolNode::Pointer aNode) | |
123 | { | |
124 | pools.push_back(aNode); | |
125 | } | |
126 | ||
127 | void * | |
128 | DelayVector::Id::operator new(size_t size) | |
129 | { | |
130 | DelayPools::MemoryUsed += sizeof (Id); | |
131 | return ::operator new (size); | |
132 | } | |
133 | ||
134 | void | |
135 | DelayVector::Id::operator delete (void *address) | |
136 | { | |
137 | DelayPools::MemoryUsed -= sizeof (Id); | |
138 | ::operator delete (address); | |
139 | } | |
140 | ||
1e5562e3 | 141 | DelayVector::Id::Id(DelayVector::Pointer aDelayVector, CompositeSelectionDetails &details) : theVector(aDelayVector) |
b67e2c8c | 142 | { |
bf8fe701 | 143 | debugs(77, 3, "DelayVector::Id::Id"); |
b67e2c8c | 144 | DelayVector::iterator pos = theVector->pools.begin(); |
62e76326 | 145 | |
1e5562e3 | 146 | while (pos != theVector->pools.end()) { |
147 | ids.push_back ((*pos)->id (details)); | |
62e76326 | 148 | ++pos; |
b67e2c8c | 149 | } |
150 | } | |
151 | ||
2f44bd34 | 152 | DelayVector::Id::~Id() |
153 | { | |
bf8fe701 | 154 | debugs(77, 3, "DelayVector::Id::~Id"); |
2f44bd34 | 155 | } |
156 | ||
b67e2c8c | 157 | int |
a748a390 | 158 | DelayVector::Id::bytesWanted (int minimum, int maximum) const |
b67e2c8c | 159 | { |
a748a390 | 160 | int nbytes = maximum; |
b67e2c8c | 161 | const_iterator pos = ids.begin(); |
62e76326 | 162 | |
b67e2c8c | 163 | while (pos != ids.end()) { |
a748a390 | 164 | nbytes = min (nbytes, (*pos)->bytesWanted(minimum, nbytes)); |
62e76326 | 165 | ++pos; |
b67e2c8c | 166 | } |
62e76326 | 167 | |
a748a390 | 168 | nbytes = max(minimum, nbytes); |
b67e2c8c | 169 | return nbytes; |
170 | } | |
171 | ||
172 | void | |
173 | DelayVector::Id::bytesIn(int qty) | |
174 | { | |
175 | iterator pos = ids.begin(); | |
62e76326 | 176 | |
b67e2c8c | 177 | while (pos != ids.end()) { |
62e76326 | 178 | (*pos)->bytesIn(qty); |
179 | ++pos; | |
b67e2c8c | 180 | } |
a46d2c0e | 181 | |
182 | theVector->kickReads(); | |
183 | } | |
184 | ||
185 | void | |
186 | DelayVector::Id::delayRead(DeferredRead const &aRead) | |
187 | { | |
188 | theVector->delayRead(aRead); | |
b67e2c8c | 189 | } |
62e76326 | 190 | |
b67e2c8c | 191 | #endif |