]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Kids.cc
Merged from trunk
[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 #include "protos.h"
11
12 Kids TheKids;
13 KidName TheKidName;
14
15 Kids::Kids()
16 {
17 }
18
19 /// maintain n kids
20 void Kids::init()
21 {
22 if (storage.size() > 0)
23 storage.clean();
24
25 storage.reserve(NumberOfKids());
26
27 char kid_name[32];
28
29 // add Kid records for all workers
30 for (int i = 0; i < Config.workers; ++i) {
31 snprintf(kid_name, sizeof(kid_name), "(squid-%d)", (int)(storage.size()+1));
32 storage.push_back(Kid(kid_name));
33 }
34
35 // add Kid records for all disk processes
36 // (XXX: some cache_dirs do not need this)
37 for (int i = 0; i < Config.cacheSwap.n_configured; ++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
49 /// returns kid by pid
50 Kid* 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
63 Kid& Kids::get(size_t i)
64 {
65 assert(i < count());
66 return storage[i];
67 }
68
69 /// whether all kids are hopeless
70 bool 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
80 bool 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
89 /// whether some kids died from a given signal
90 bool Kids::someSignaled(const int sgnl) const
91 {
92 for (size_t i = 0; i < storage.size(); ++i) {
93 if (storage[i].signaled(sgnl))
94 return true;
95 }
96 return false;
97 }
98
99 /// whether some kids are running
100 bool 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
110 bool 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;
117 }
118
119 /// returns the number of kids
120 size_t Kids::count() const
121 {
122 return storage.size();
123 }