]>
Commit | Line | Data |
---|---|---|
40daaeb8 AR |
1 | /* |
2 | * $Id$ | |
3 | * | |
4 | * DEBUG: section 54 Interprocess Communication | |
5 | * | |
6 | */ | |
7 | ||
f7f3304a | 8 | #include "squid.h" |
96a20046 | 9 | #include "base/TextException.h" |
40daaeb8 | 10 | #include "ipc/Kids.h" |
095ec2b1 | 11 | #include "protos.h" |
40daaeb8 AR |
12 | |
13 | Kids TheKids; | |
9de6c973 | 14 | KidName TheKidName; |
40daaeb8 AR |
15 | |
16 | Kids::Kids() | |
17 | { | |
18 | } | |
19 | ||
20 | /// maintain n kids | |
095ec2b1 | 21 | void Kids::init() |
40daaeb8 | 22 | { |
40daaeb8 AR |
23 | if (storage.size() > 0) |
24 | storage.clean(); | |
25 | ||
095ec2b1 | 26 | storage.reserve(NumberOfKids()); |
40daaeb8 | 27 | |
10cefb7b | 28 | char kid_name[32]; |
ba568924 | 29 | |
095ec2b1 AR |
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 | |
3b581957 | 37 | for (int i = 0; i < Config.cacheSwap.n_strands; ++i) { |
095ec2b1 | 38 | snprintf(kid_name, sizeof(kid_name), "(squid-disk-%d)", (int)(storage.size()+1)); |
40daaeb8 AR |
39 | storage.push_back(Kid(kid_name)); |
40 | } | |
10cefb7b | 41 | |
ba568924 | 42 | // if coordination is needed, add a Kid record for Coordinator |
095ec2b1 AR |
43 | if (storage.size() > 1) { |
44 | snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(storage.size()+1)); | |
10cefb7b | 45 | storage.push_back(Kid(kid_name)); |
46 | } | |
96a20046 DK |
47 | |
48 | Must(storage.size() == static_cast<size_t>(NumberOfKids())); | |
40daaeb8 AR |
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 | { | |
1dc746da | 67 | assert(i < count()); |
40daaeb8 AR |
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 | ||
ca4b9ee6 DK |
91 | /// whether some kids died from a given signal |
92 | bool Kids::someSignaled(const int sgnl) const | |
40daaeb8 AR |
93 | { |
94 | for (size_t i = 0; i < storage.size(); ++i) { | |
ca4b9ee6 DK |
95 | if (storage[i].signaled(sgnl)) |
96 | return true; | |
40daaeb8 | 97 | } |
ca4b9ee6 DK |
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; | |
40daaeb8 AR |
119 | } |
120 | ||
121 | /// returns the number of kids | |
122 | size_t Kids::count() const | |
123 | { | |
124 | return storage.size(); | |
125 | } |