]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Kids.cc
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 54 Interprocess Communication */
12 #include "base/TextException.h"
15 #include "SquidConfig.h"
30 storage
.reserve(NumberOfKids());
32 for (int i
= 0; i
< Config
.workers
; ++i
)
33 storage
.emplace_back("squid", storage
.size() + 1);
35 // add Kid records for all disk processes
36 for (int i
= 0; i
< Config
.cacheSwap
.n_strands
; ++i
)
37 storage
.emplace_back("squid-disk", storage
.size() + 1);
39 // if coordination is needed, add a Kid record for Coordinator
40 if (storage
.size() > 1)
41 storage
.emplace_back("squid-coord", storage
.size() + 1);
43 Must(storage
.size() == static_cast<size_t>(NumberOfKids()));
46 /// returns kid by pid
47 Kid
* Kids::find(pid_t pid
)
52 for (size_t i
= 0; i
< storage
.size(); ++i
) {
53 if (storage
[i
].getPid() == pid
)
59 /// returns the kid by index, useful for kids iteration
60 Kid
& Kids::get(size_t i
)
66 /// whether all kids are hopeless
67 bool Kids::allHopeless() const
69 for (size_t i
= 0; i
< storage
.size(); ++i
) {
70 if (!storage
[i
].hopeless())
77 Kids::forgetAllFailures()
79 for (auto &kid
: storage
)
84 Kids::forgetOldFailures()
86 time_t nextCheckDelay
= 0;
87 for (auto &kid
: storage
) {
91 const auto deathDuration
= kid
.deathDuration(); // protect from time changes
92 if (Config
.hopelessKidRevivalDelay
<= deathDuration
) {
93 kid
.forgetFailures(); // this kid will be revived now
97 const auto remainingDeathTime
= Config
.hopelessKidRevivalDelay
- deathDuration
;
98 assert(remainingDeathTime
> 0);
99 if (remainingDeathTime
< nextCheckDelay
|| !nextCheckDelay
)
100 nextCheckDelay
= remainingDeathTime
;
102 return nextCheckDelay
; // still zero if there were no still-hopeless kids
105 /// whether all kids called exited happy
106 bool Kids::allExitedHappy() const
108 for (size_t i
= 0; i
< storage
.size(); ++i
) {
109 if (!storage
[i
].exitedHappy())
115 /// whether some kids died from a given signal
116 bool Kids::someSignaled(const int sgnl
) const
118 for (size_t i
= 0; i
< storage
.size(); ++i
) {
119 if (storage
[i
].signaled(sgnl
))
125 /// whether some kids are running
126 bool Kids::someRunning() const
128 for (size_t i
= 0; i
< storage
.size(); ++i
) {
129 if (storage
[i
].running())
135 /// whether some kids should be restarted by master
136 bool Kids::shouldRestartSome() const
138 for (size_t i
= 0; i
< storage
.size(); ++i
) {
139 if (storage
[i
].shouldRestart())
145 /// returns the number of kids
146 size_t Kids::count() const
148 return storage
.size();