]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add base class for registered runners that work with shared memory.
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Tue, 4 Oct 2011 17:26:58 +0000 (21:26 +0400)
committerDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Tue, 4 Oct 2011 17:26:58 +0000 (21:26 +0400)
Shared memory runners do two main things:

* create shared memory segments
* open shared memory segments created earlier

Each runner has to decide whether it needs to create and/or open
shared memory segments.  Common runners share (some) logic in making
this decisions.  The purpose of this patch is to implement this logic
in a single place to allow easy reuse and avoid duplication.

src/ipc/mem/Segment.cc
src/ipc/mem/Segment.h
src/tests/stub_tools.cc

index 5702fd0f6a9f5ecd72adbcc0f9c1d77e3112f1a3..ca31f3ca0b2418ea859ea8c86aff8c376431d154 100644 (file)
@@ -256,3 +256,23 @@ Ipc::Mem::Segment::checkSupport(const char *const context)
 }
 
 #endif // HAVE_SHM
+
+void
+Ipc::Mem::RegisteredRunner::run(const RunnerRegistry &r)
+{
+    // If Squid is built with real segments, we create() real segments
+    // in the master process only.  Otherwise, we create() fake
+    // segments in each worker process.  We assume that only workers
+    // need and can work with fake segments.
+#if HAVE_SHM
+    if (IamMasterProcess())
+#else
+    if (IamWorker())
+#endif
+        create(r);
+
+    // we assume that master process does not need shared segments
+    // unless it is also a worker
+    if (!InDaemonMode() || !IamMasterProcess())
+        open(r);
+}
index b82ac4fab730773365ad03621e767bdab65838bb..28966f298fb57d66b6702a2e99cd723446d70333 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef SQUID_IPC_MEM_SEGMENT_H
 #define SQUID_IPC_MEM_SEGMENT_H
 
+#include "base/RunnersRegistry.h"
 #include "SquidString.h"
 
 namespace Ipc
@@ -65,6 +66,22 @@ private:
     bool doUnlink; ///< whether the segment should be unlinked on destruction
 };
 
+/// Base class for runners that create and open shared memory segments.
+/// First may run create() method and then open().
+class RegisteredRunner: public ::RegisteredRunner
+{
+public:
+    /* RegisteredRunner API */
+    virtual void run(const RunnerRegistry &r);
+
+protected:
+    /// called when the runner should create a new memory segment
+    virtual void create(const RunnerRegistry &) = 0;
+    /// called when the runner should open a previously created segment,
+    /// not needed if segments are opened in constructor or init methods
+    virtual void open(const RunnerRegistry &) {}
+};
+
 } // namespace Mem
 
 } // namespace Ipc
index 014b561ba667d870662cf518f6ef107de7cdd8ca..f86d0d76057c0145566712d71ebe6c4ef27bfc48 100644 (file)
@@ -75,6 +75,13 @@ IamMasterProcess()
     return false;
 }
 
+bool
+InDaemonMode()
+{
+    fprintf(stderr, "Not implemented");
+    return false;
+}
+
 bool
 UsingSmp()
 {