]>
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());
34 // add Kid records for all workers
35 for (int i
= 0; i
< Config
.workers
; ++i
) {
36 snprintf(kid_name
, sizeof(kid_name
), "(squid-%d)", (int)(storage
.size()+1));
37 storage
.push_back(Kid(kid_name
));
40 // add Kid records for all disk processes
41 for (int i
= 0; i
< Config
.cacheSwap
.n_strands
; ++i
) {
42 snprintf(kid_name
, sizeof(kid_name
), "(squid-disk-%d)", (int)(storage
.size()+1));
43 storage
.push_back(Kid(kid_name
));
46 // if coordination is needed, add a Kid record for Coordinator
47 if (storage
.size() > 1) {
48 snprintf(kid_name
, sizeof(kid_name
), "(squid-coord-%d)", (int)(storage
.size()+1));
49 storage
.push_back(Kid(kid_name
));
52 Must(storage
.size() == static_cast<size_t>(NumberOfKids()));
55 /// returns kid by pid
56 Kid
* Kids::find(pid_t pid
)
61 for (size_t i
= 0; i
< storage
.size(); ++i
) {
62 if (storage
[i
].getPid() == pid
)
68 /// returns the kid by index, useful for kids iteration
69 Kid
& Kids::get(size_t i
)
75 /// whether all kids are hopeless
76 bool Kids::allHopeless() const
78 for (size_t i
= 0; i
< storage
.size(); ++i
) {
79 if (!storage
[i
].hopeless())
86 Kids::forgetAllFailures()
88 for (auto &kid
: storage
)
93 Kids::forgetOldFailures()
95 time_t nextCheckDelay
= 0;
96 for (auto &kid
: storage
) {
100 const auto deathDuration
= kid
.deathDuration(); // protect from time changes
101 if (Config
.hopelessKidRevivalDelay
<= deathDuration
) {
102 kid
.forgetFailures(); // this kid will be revived now
106 const auto remainingDeathTime
= Config
.hopelessKidRevivalDelay
- deathDuration
;
107 assert(remainingDeathTime
> 0);
108 if (remainingDeathTime
< nextCheckDelay
|| !nextCheckDelay
)
109 nextCheckDelay
= remainingDeathTime
;
111 return nextCheckDelay
; // still zero if there were no still-hopeless kids
114 /// whether all kids called exited happy
115 bool Kids::allExitedHappy() const
117 for (size_t i
= 0; i
< storage
.size(); ++i
) {
118 if (!storage
[i
].exitedHappy())
124 /// whether some kids died from a given signal
125 bool Kids::someSignaled(const int sgnl
) const
127 for (size_t i
= 0; i
< storage
.size(); ++i
) {
128 if (storage
[i
].signaled(sgnl
))
134 /// whether some kids are running
135 bool Kids::someRunning() const
137 for (size_t i
= 0; i
< storage
.size(); ++i
) {
138 if (storage
[i
].running())
144 /// whether some kids should be restarted by master
145 bool Kids::shouldRestartSome() const
147 for (size_t i
= 0; i
< storage
.size(); ++i
) {
148 if (storage
[i
].shouldRestart())
154 /// returns the number of kids
155 size_t Kids::count() const
157 return storage
.size();