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