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