]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/Kids.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / Kids.cc
index 836e97bad8f3e4db8c1c9007c00a02ea3853844a..7cb5704ea5511ad132572d822bb221d5224c5330 100644 (file)
@@ -1,12 +1,19 @@
 /*
- * $Id$
- *
- * DEBUG: section 54    Interprocess Communication
+ * Copyright (C) 1996-2017 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);
+    storage.clear();
 
-    if (storage.size() > 0)
-        storage.clean();
-
-    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
@@ -115,3 +127,4 @@ size_t Kids::count() const
 {
     return storage.size();
 }
+