]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Kids.cc
Merged from parent (trunk 11270, circa 3.2.0.5+)
[thirdparty/squid.git] / src / ipc / Kids.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #include "config.h"
9 #include "ipc/Kids.h"
10
11 Kids TheKids;
12 KidName TheKidName;
13
14 Kids::Kids()
15 {
16 }
17
18 /// maintain n kids
19 void Kids::init(size_t n)
20 {
21 assert(n > 0);
22
23 if (storage.size() > 0)
24 storage.clean();
25
26 storage.reserve(n);
27
28 char kid_name[32];
29
30 // add Kid records for all n main strands
31 for (size_t i = 1; i <= n; ++i) {
32 snprintf(kid_name, sizeof(kid_name), "(squid-%d)", (int)i);
33 storage.push_back(Kid(kid_name));
34 }
35
36 // if coordination is needed, add a Kid record for Coordinator
37 if (n > 1) {
38 snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(n + 1));
39 storage.push_back(Kid(kid_name));
40 }
41 }
42
43 /// returns kid by pid
44 Kid* Kids::find(pid_t pid)
45 {
46 assert(pid > 0);
47 assert(count() > 0);
48
49 for (size_t i = 0; i < storage.size(); ++i) {
50 if (storage[i].getPid() == pid)
51 return &storage[i];
52 }
53 return NULL;
54 }
55
56 /// returns the kid by index, useful for kids iteration
57 Kid& Kids::get(size_t i)
58 {
59 assert(i < count());
60 return storage[i];
61 }
62
63 /// whether all kids are hopeless
64 bool Kids::allHopeless() const
65 {
66 for (size_t i = 0; i < storage.size(); ++i) {
67 if (!storage[i].hopeless())
68 return false;
69 }
70 return true;
71 }
72
73 /// whether all kids called exited happy
74 bool Kids::allExitedHappy() const
75 {
76 for (size_t i = 0; i < storage.size(); ++i) {
77 if (!storage[i].exitedHappy())
78 return false;
79 }
80 return true;
81 }
82
83 /// whether all kids died from a given signal
84 bool Kids::allSignaled(int sgnl) const
85 {
86 for (size_t i = 0; i < storage.size(); ++i) {
87 if (!storage[i].signaled(sgnl))
88 return false;
89 }
90 return true;
91 }
92
93 /// returns the number of kids
94 size_t Kids::count() const
95 {
96 return storage.size();
97 }