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