]>
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 | { |
40daaeb8 AR |
22 | if (storage.size() > 0) |
23 | storage.clean(); | |
24 | ||
095ec2b1 | 25 | storage.reserve(NumberOfKids()); |
40daaeb8 | 26 | |
10cefb7b | 27 | char kid_name[32]; |
ba568924 | 28 | |
095ec2b1 AR |
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 | |
3b581957 | 36 | for (int i = 0; i < Config.cacheSwap.n_strands; ++i) { |
095ec2b1 | 37 | snprintf(kid_name, sizeof(kid_name), "(squid-disk-%d)", (int)(storage.size()+1)); |
40daaeb8 AR |
38 | storage.push_back(Kid(kid_name)); |
39 | } | |
10cefb7b | 40 | |
ba568924 | 41 | // if coordination is needed, add a Kid record for Coordinator |
095ec2b1 AR |
42 | if (storage.size() > 1) { |
43 | snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(storage.size()+1)); | |
10cefb7b | 44 | storage.push_back(Kid(kid_name)); |
45 | } | |
96a20046 DK |
46 | |
47 | Must(storage.size() == static_cast<size_t>(NumberOfKids())); | |
40daaeb8 AR |
48 | } |
49 | ||
50 | /// returns kid by pid | |
51 | Kid* Kids::find(pid_t pid) | |
52 | { | |
53 | assert(pid > 0); | |
54 | assert(count() > 0); | |
55 | ||
56 | for (size_t i = 0; i < storage.size(); ++i) { | |
57 | if (storage[i].getPid() == pid) | |
58 | return &storage[i]; | |
59 | } | |
60 | return NULL; | |
61 | } | |
62 | ||
63 | /// returns the kid by index, useful for kids iteration | |
64 | Kid& Kids::get(size_t i) | |
65 | { | |
1dc746da | 66 | assert(i < count()); |
40daaeb8 AR |
67 | return storage[i]; |
68 | } | |
69 | ||
70 | /// whether all kids are hopeless | |
71 | bool Kids::allHopeless() const | |
72 | { | |
73 | for (size_t i = 0; i < storage.size(); ++i) { | |
74 | if (!storage[i].hopeless()) | |
75 | return false; | |
76 | } | |
77 | return true; | |
78 | } | |
79 | ||
80 | /// whether all kids called exited happy | |
81 | bool Kids::allExitedHappy() const | |
82 | { | |
83 | for (size_t i = 0; i < storage.size(); ++i) { | |
84 | if (!storage[i].exitedHappy()) | |
85 | return false; | |
86 | } | |
87 | return true; | |
88 | } | |
89 | ||
ca4b9ee6 DK |
90 | /// whether some kids died from a given signal |
91 | bool Kids::someSignaled(const int sgnl) const | |
40daaeb8 AR |
92 | { |
93 | for (size_t i = 0; i < storage.size(); ++i) { | |
ca4b9ee6 DK |
94 | if (storage[i].signaled(sgnl)) |
95 | return true; | |
40daaeb8 | 96 | } |
ca4b9ee6 DK |
97 | return false; |
98 | } | |
99 | ||
100 | /// whether some kids are running | |
101 | bool Kids::someRunning() const | |
102 | { | |
103 | for (size_t i = 0; i < storage.size(); ++i) { | |
104 | if (storage[i].running()) | |
105 | return true; | |
106 | } | |
107 | return false; | |
108 | } | |
109 | ||
110 | /// whether some kids should be restarted by master | |
111 | bool Kids::shouldRestartSome() const | |
112 | { | |
113 | for (size_t i = 0; i < storage.size(); ++i) { | |
114 | if (storage[i].shouldRestart()) | |
115 | return true; | |
116 | } | |
117 | return false; | |
40daaeb8 AR |
118 | } |
119 | ||
120 | /// returns the number of kids | |
121 | size_t Kids::count() const | |
122 | { | |
123 | return storage.size(); | |
124 | } |