]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/Kids.cc
Boilerplate: update copyright blurbs on Squid helpers
[thirdparty/squid.git] / src / ipc / Kids.cc
CommitLineData
40daaeb8 1/*
40daaeb8 2 * DEBUG: section 54 Interprocess Communication
40daaeb8
AR
3 */
4
f7f3304a 5#include "squid.h"
96a20046 6#include "base/TextException.h"
67679543 7#include "globals.h"
40daaeb8 8#include "ipc/Kids.h"
4d5904f7 9#include "SquidConfig.h"
602d9612 10#include "tools.h"
40daaeb8
AR
11
12Kids TheKids;
9de6c973 13KidName TheKidName;
40daaeb8
AR
14
15Kids::Kids()
16{
17}
18
19/// maintain n kids
095ec2b1 20void Kids::init()
40daaeb8 21{
c33a88ca 22 storage.clear();
40daaeb8 23
095ec2b1 24 storage.reserve(NumberOfKids());
40daaeb8 25
10cefb7b 26 char kid_name[32];
ba568924 27
095ec2b1
AR
28 // add Kid records for all workers
29 for (int i = 0; i < Config.workers; ++i) {
30 snprintf(kid_name, sizeof(kid_name), "(squid-%d)", (int)(storage.size()+1));
31 storage.push_back(Kid(kid_name));
32 }
33
34 // add Kid records for all disk processes
3b581957 35 for (int i = 0; i < Config.cacheSwap.n_strands; ++i) {
095ec2b1 36 snprintf(kid_name, sizeof(kid_name), "(squid-disk-%d)", (int)(storage.size()+1));
40daaeb8
AR
37 storage.push_back(Kid(kid_name));
38 }
10cefb7b 39
ba568924 40 // if coordination is needed, add a Kid record for Coordinator
095ec2b1
AR
41 if (storage.size() > 1) {
42 snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(storage.size()+1));
10cefb7b 43 storage.push_back(Kid(kid_name));
44 }
96a20046
DK
45
46 Must(storage.size() == static_cast<size_t>(NumberOfKids()));
40daaeb8
AR
47}
48
49/// returns kid by pid
50Kid* Kids::find(pid_t pid)
51{
52 assert(pid > 0);
53 assert(count() > 0);
54
55 for (size_t i = 0; i < storage.size(); ++i) {
56 if (storage[i].getPid() == pid)
57 return &storage[i];
58 }
59 return NULL;
60}
61
62/// returns the kid by index, useful for kids iteration
63Kid& Kids::get(size_t i)
64{
1dc746da 65 assert(i < count());
40daaeb8
AR
66 return storage[i];
67}
68
69/// whether all kids are hopeless
70bool Kids::allHopeless() const
71{
72 for (size_t i = 0; i < storage.size(); ++i) {
73 if (!storage[i].hopeless())
74 return false;
75 }
76 return true;
77}
78
79/// whether all kids called exited happy
80bool Kids::allExitedHappy() const
81{
82 for (size_t i = 0; i < storage.size(); ++i) {
83 if (!storage[i].exitedHappy())
84 return false;
85 }
86 return true;
87}
88
ca4b9ee6
DK
89/// whether some kids died from a given signal
90bool Kids::someSignaled(const int sgnl) const
40daaeb8
AR
91{
92 for (size_t i = 0; i < storage.size(); ++i) {
ca4b9ee6
DK
93 if (storage[i].signaled(sgnl))
94 return true;
40daaeb8 95 }
ca4b9ee6
DK
96 return false;
97}
98
99/// whether some kids are running
100bool Kids::someRunning() const
101{
102 for (size_t i = 0; i < storage.size(); ++i) {
103 if (storage[i].running())
104 return true;
105 }
106 return false;
107}
108
109/// whether some kids should be restarted by master
110bool Kids::shouldRestartSome() const
111{
112 for (size_t i = 0; i < storage.size(); ++i) {
113 if (storage[i].shouldRestart())
114 return true;
115 }
116 return false;
40daaeb8
AR
117}
118
119/// returns the number of kids
120size_t Kids::count() const
121{
122 return storage.size();
123}