]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/Kids.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / Kids.cc
index 7e15ceb7d6e6a2ca320c679273d7abe16e6fcd9d..717cf47615e25a6bf286424ff66c7dc7f75c52e3 100644 (file)
@@ -1,12 +1,19 @@
 /*
- * $Id$
- *
- * DEBUG: section 54    Interprocess Communication
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
  *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
-#include "config.h"
+/* DEBUG: section 54    Interprocess Communication */
+
+#include "squid.h"
+#include "base/TextException.h"
+#include "globals.h"
 #include "ipc/Kids.h"
+#include "SquidConfig.h"
+#include "tools.h"
 
 Kids TheKids;
 KidName TheKidName;
@@ -16,28 +23,33 @@ Kids::Kids()
 }
 
 /// maintain n kids
-void Kids::init(size_t n)
+void Kids::init()
 {
-    assert(n > 0);
-
-    if (storage.size() > 0)
-        storage.clean();
+    storage.clear();
 
-    storage.reserve(n);
+    storage.reserve(NumberOfKids());
 
     char kid_name[32];
 
-    // add Kid records for all n main strands
-    for (size_t i = 1; i <= n; ++i) {
-        snprintf(kid_name, sizeof(kid_name), "(squid-%d)", (int)i);
+    // add Kid records for all workers
+    for (int i = 0; i < Config.workers; ++i) {
+        snprintf(kid_name, sizeof(kid_name), "(squid-%d)", (int)(storage.size()+1));
+        storage.push_back(Kid(kid_name));
+    }
+
+    // add Kid records for all disk processes
+    for (int i = 0; i < Config.cacheSwap.n_strands; ++i) {
+        snprintf(kid_name, sizeof(kid_name), "(squid-disk-%d)", (int)(storage.size()+1));
         storage.push_back(Kid(kid_name));
     }
 
     // if coordination is needed, add a Kid record for Coordinator
-    if (n > 1) {
-        snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(n + 1));
+    if (storage.size() > 1) {
+        snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(storage.size()+1));
         storage.push_back(Kid(kid_name));
     }
+
+    Must(storage.size() == static_cast<size_t>(NumberOfKids()));
 }
 
 /// returns kid by pid
@@ -56,7 +68,7 @@ Kid* Kids::find(pid_t pid)
 /// returns the kid by index, useful for kids iteration
 Kid& Kids::get(size_t i)
 {
-    assert(i >= 0 && i < count());
+    assert(i < count());
     return storage[i];
 }
 
@@ -80,14 +92,34 @@ bool Kids::allExitedHappy() const
     return true;
 }
 
-/// whether all kids died from a given signal
-bool Kids::allSignaled(int sgnl) const
+/// whether some kids died from a given signal
+bool Kids::someSignaled(const int sgnl) const
 {
     for (size_t i = 0; i < storage.size(); ++i) {
-        if (!storage[i].signaled(sgnl))
-            return false;
+        if (storage[i].signaled(sgnl))
+            return true;
     }
-    return true;
+    return false;
+}
+
+/// whether some kids are running
+bool Kids::someRunning() const
+{
+    for (size_t i = 0; i < storage.size(); ++i) {
+        if (storage[i].running())
+            return true;
+    }
+    return false;
+}
+
+/// whether some kids should be restarted by master
+bool Kids::shouldRestartSome() const
+{
+    for (size_t i = 0; i < storage.size(); ++i) {
+        if (storage[i].shouldRestart())
+            return true;
+    }
+    return false;
 }
 
 /// returns the number of kids
@@ -95,3 +127,4 @@ size_t Kids::count() const
 {
     return storage.size();
 }
+