]>
Commit | Line | Data |
---|---|---|
40daaeb8 | 1 | /* |
bbc27441 AJ |
2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors |
3 | * | |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
40daaeb8 AR |
7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 54 Interprocess Communication */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
96a20046 | 12 | #include "base/TextException.h" |
67679543 | 13 | #include "globals.h" |
40daaeb8 | 14 | #include "ipc/Kids.h" |
4d5904f7 | 15 | #include "SquidConfig.h" |
602d9612 | 16 | #include "tools.h" |
40daaeb8 AR |
17 | |
18 | Kids TheKids; | |
9de6c973 | 19 | KidName TheKidName; |
40daaeb8 AR |
20 | |
21 | Kids::Kids() | |
22 | { | |
23 | } | |
24 | ||
25 | /// maintain n kids | |
095ec2b1 | 26 | void Kids::init() |
40daaeb8 | 27 | { |
c33a88ca | 28 | storage.clear(); |
40daaeb8 | 29 | |
095ec2b1 | 30 | storage.reserve(NumberOfKids()); |
40daaeb8 | 31 | |
10cefb7b | 32 | char kid_name[32]; |
ba568924 | 33 | |
095ec2b1 AR |
34 | // add Kid records for all workers |
35 | for (int i = 0; i < Config.workers; ++i) { | |
36 | snprintf(kid_name, sizeof(kid_name), "(squid-%d)", (int)(storage.size()+1)); | |
37 | storage.push_back(Kid(kid_name)); | |
38 | } | |
39 | ||
40 | // add Kid records for all disk processes | |
3b581957 | 41 | for (int i = 0; i < Config.cacheSwap.n_strands; ++i) { |
095ec2b1 | 42 | snprintf(kid_name, sizeof(kid_name), "(squid-disk-%d)", (int)(storage.size()+1)); |
40daaeb8 AR |
43 | storage.push_back(Kid(kid_name)); |
44 | } | |
10cefb7b | 45 | |
ba568924 | 46 | // if coordination is needed, add a Kid record for Coordinator |
095ec2b1 AR |
47 | if (storage.size() > 1) { |
48 | snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(storage.size()+1)); | |
10cefb7b | 49 | storage.push_back(Kid(kid_name)); |
50 | } | |
96a20046 DK |
51 | |
52 | Must(storage.size() == static_cast<size_t>(NumberOfKids())); | |
40daaeb8 AR |
53 | } |
54 | ||
55 | /// returns kid by pid | |
56 | Kid* Kids::find(pid_t pid) | |
57 | { | |
58 | assert(pid > 0); | |
59 | assert(count() > 0); | |
60 | ||
61 | for (size_t i = 0; i < storage.size(); ++i) { | |
62 | if (storage[i].getPid() == pid) | |
63 | return &storage[i]; | |
64 | } | |
65 | return NULL; | |
66 | } | |
67 | ||
68 | /// returns the kid by index, useful for kids iteration | |
69 | Kid& Kids::get(size_t i) | |
70 | { | |
1dc746da | 71 | assert(i < count()); |
40daaeb8 AR |
72 | return storage[i]; |
73 | } | |
74 | ||
75 | /// whether all kids are hopeless | |
76 | bool Kids::allHopeless() const | |
77 | { | |
78 | for (size_t i = 0; i < storage.size(); ++i) { | |
79 | if (!storage[i].hopeless()) | |
80 | return false; | |
81 | } | |
82 | return true; | |
83 | } | |
84 | ||
85 | /// whether all kids called exited happy | |
86 | bool Kids::allExitedHappy() const | |
87 | { | |
88 | for (size_t i = 0; i < storage.size(); ++i) { | |
89 | if (!storage[i].exitedHappy()) | |
90 | return false; | |
91 | } | |
92 | return true; | |
93 | } | |
94 | ||
ca4b9ee6 DK |
95 | /// whether some kids died from a given signal |
96 | bool Kids::someSignaled(const int sgnl) const | |
40daaeb8 AR |
97 | { |
98 | for (size_t i = 0; i < storage.size(); ++i) { | |
ca4b9ee6 DK |
99 | if (storage[i].signaled(sgnl)) |
100 | return true; | |
40daaeb8 | 101 | } |
ca4b9ee6 DK |
102 | return false; |
103 | } | |
104 | ||
105 | /// whether some kids are running | |
106 | bool Kids::someRunning() const | |
107 | { | |
108 | for (size_t i = 0; i < storage.size(); ++i) { | |
109 | if (storage[i].running()) | |
110 | return true; | |
111 | } | |
112 | return false; | |
113 | } | |
114 | ||
115 | /// whether some kids should be restarted by master | |
116 | bool Kids::shouldRestartSome() const | |
117 | { | |
118 | for (size_t i = 0; i < storage.size(); ++i) { | |
119 | if (storage[i].shouldRestart()) | |
120 | return true; | |
121 | } | |
122 | return false; | |
40daaeb8 AR |
123 | } |
124 | ||
125 | /// returns the number of kids | |
126 | size_t Kids::count() const | |
127 | { | |
128 | return storage.size(); | |
129 | } |