]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayVector.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / DelayVector.cc
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: section 77 Delay Pools */
10
11 #include "squid.h"
12
13 #if USE_DELAY_POOLS
14 #include "comm/Connection.h"
15 #include "CommRead.h"
16 #include "DelayVector.h"
17
18 void *
19 DelayVector::operator new(size_t size)
20 {
21 DelayPools::MemoryUsed += sizeof (DelayVector);
22 return ::operator new (size);
23 }
24
25 void
26 DelayVector::operator delete (void *address)
27 {
28 DelayPools::MemoryUsed -= sizeof (DelayVector);
29 ::operator delete (address);
30 }
31
32 DelayVector::DelayVector()
33 {
34 DelayPools::registerForUpdates (this);
35 }
36
37 DelayVector::~DelayVector()
38 {
39 DelayPools::deregisterForUpdates (this);
40 }
41
42 void
43 DelayVector::stats(StoreEntry * sentry)
44 {
45 iterator pos = pools.begin();
46
47 while (pos != pools.end()) {
48 (*pos)->stats(sentry);
49 ++pos;
50 }
51 }
52
53 void
54 DelayVector::dump(StoreEntry *entry) const
55 {
56 const_iterator pos = pools.begin();
57
58 while (pos != pools.end()) {
59 (*pos)->dump(entry);
60 ++pos;
61 }
62 }
63
64 void
65 DelayVector::update(int incr)
66 {
67 /*
68 * Each pool updates itself,
69 * but we may have deferred reads waiting on the pool as a whole.
70 */
71
72 kickReads();
73 }
74
75 void
76 DelayVector::parse()
77 {
78 iterator pos = pools.begin();
79
80 while (pos != pools.end()) {
81 (*pos)->parse();
82 ++pos;
83 }
84 }
85
86 DelayIdComposite::Pointer
87 DelayVector::id(CompositeSelectionDetails &details)
88 {
89 return new Id(this, details);
90 }
91
92 void
93 DelayVector::push_back(CompositePoolNode::Pointer aNode)
94 {
95 pools.push_back(aNode);
96 }
97
98 void *
99 DelayVector::Id::operator new(size_t size)
100 {
101 DelayPools::MemoryUsed += sizeof (Id);
102 return ::operator new (size);
103 }
104
105 void
106 DelayVector::Id::operator delete (void *address)
107 {
108 DelayPools::MemoryUsed -= sizeof (Id);
109 ::operator delete (address);
110 }
111
112 DelayVector::Id::Id(DelayVector::Pointer aDelayVector, CompositeSelectionDetails &details) : theVector(aDelayVector)
113 {
114 debugs(77, 3, "DelayVector::Id::Id");
115 DelayVector::iterator pos = theVector->pools.begin();
116
117 while (pos != theVector->pools.end()) {
118 ids.push_back ((*pos)->id (details));
119 ++pos;
120 }
121 }
122
123 DelayVector::Id::~Id()
124 {
125 debugs(77, 3, "DelayVector::Id::~Id");
126 }
127
128 int
129 DelayVector::Id::bytesWanted (int minimum, int maximum) const
130 {
131 int nbytes = maximum;
132 const_iterator pos = ids.begin();
133
134 while (pos != ids.end()) {
135 nbytes = min (nbytes, (*pos)->bytesWanted(minimum, nbytes));
136 ++pos;
137 }
138
139 nbytes = max(minimum, nbytes);
140 return nbytes;
141 }
142
143 void
144 DelayVector::Id::bytesIn(int qty)
145 {
146 iterator pos = ids.begin();
147
148 while (pos != ids.end()) {
149 (*pos)->bytesIn(qty);
150 ++pos;
151 }
152
153 theVector->kickReads();
154 }
155
156 void
157 DelayVector::Id::delayRead(DeferredRead const &aRead)
158 {
159 theVector->delayRead(aRead);
160 }
161
162 #endif
163