3 * $Id: DelayVector.cc,v 1.8 2003/05/20 12:17:38 robertc Exp $
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>
10 * SQUID Web Proxy Cache http://www.squid-cache.org/
11 * ----------------------------------------------------------
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.
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.
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.
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.
37 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
44 #include "DelayVector.h"
48 DelayVector::operator new(size_t size
)
50 DelayPools::MemoryUsed
+= sizeof (DelayVector
);
51 return ::operator new (size
);
55 DelayVector::operator delete (void *address
)
57 DelayPools::MemoryUsed
-= sizeof (DelayVector
);
58 ::operator delete (address
);
62 DelayVector::deleteSelf() const
67 DelayVector::DelayVector()
69 DelayPools::registerForUpdates (this);
72 DelayVector::~DelayVector()
74 DelayPools::deregisterForUpdates (this);
78 DelayVector::stats(StoreEntry
* sentry
)
80 iterator pos
= pools
.begin();
82 while (pos
!= pools
.end()) {
83 (*pos
)->stats(sentry
);
89 DelayVector::dump(StoreEntry
*entry
) const
91 const_iterator pos
= pools
.begin();
93 while (pos
!= pools
.end()) {
100 DelayVector::update(int incr
)
103 * Each pool updates itself,
104 * but we may have deferred reads waiting on the pool as a whole.
113 iterator pos
= pools
.begin();
115 while (pos
!= pools
.end()) {
121 DelayIdComposite::Pointer
122 DelayVector::id(CompositeSelectionDetails
&details
)
124 return new Id(this, details
);
128 DelayVector::push_back(CompositePoolNode::Pointer aNode
)
130 pools
.push_back(aNode
);
134 DelayVector::Id::operator new(size_t size
)
136 DelayPools::MemoryUsed
+= sizeof (Id
);
137 return ::operator new (size
);
141 DelayVector::Id::operator delete (void *address
)
143 DelayPools::MemoryUsed
-= sizeof (Id
);
144 ::operator delete (address
);
148 DelayVector::Id::deleteSelf() const
153 DelayVector::Id::Id(DelayVector::Pointer aDelayVector
, CompositeSelectionDetails
&details
) : theVector(aDelayVector
)
155 debug(77,3)("DelayVector::Id::Id\n");
156 DelayVector::iterator pos
= theVector
->pools
.begin();
158 while (pos
!= theVector
->pools
.end()) {
159 ids
.push_back ((*pos
)->id (details
));
164 DelayVector::Id::~Id()
166 debug(77,3)("DelayVector::Id::~Id\n");
170 DelayVector::Id::bytesWanted (int minimum
, int maximum
) const
172 int nbytes
= maximum
;
173 const_iterator pos
= ids
.begin();
175 while (pos
!= ids
.end()) {
176 nbytes
= min (nbytes
, (*pos
)->bytesWanted(minimum
, nbytes
));
180 nbytes
= max(minimum
, nbytes
);
185 DelayVector::Id::bytesIn(int qty
)
187 iterator pos
= ids
.begin();
189 while (pos
!= ids
.end()) {
190 (*pos
)->bytesIn(qty
);
194 theVector
->kickReads();
198 DelayVector::Id::delayRead(DeferredRead
const &aRead
)
200 theVector
->delayRead(aRead
);