]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Rewrite shared memory registry runners using Ipc::Mem::RegisteredRunner.
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Tue, 4 Oct 2011 17:27:22 +0000 (21:27 +0400)
committerDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Tue, 4 Oct 2011 17:27:22 +0000 (21:27 +0400)
This allows simpler code and cleaner separation between shared segment
creation and openning.

src/DiskIO/IpcIo/IpcIoFile.cc
src/MemStore.cc
src/fs/rock/RockSwapDir.cc
src/ipc/mem/Pages.cc

index 6b3e8ddcbddcf12e49606887baeea820a19751c8..a00a8035cecdbc26c119b217b2404a04ee7046d3 100644 (file)
@@ -831,14 +831,16 @@ DiskerClose(const String &path)
 
 
 /// initializes shared memory segments used by IpcIoFile
-class IpcIoRr: public RegisteredRunner
+class IpcIoRr: public Ipc::Mem::RegisteredRunner
 {
 public:
     /* RegisteredRunner API */
     IpcIoRr(): owner(NULL) {}
-    virtual void run(const RunnerRegistry &);
     virtual ~IpcIoRr();
 
+protected:
+    virtual void create(const RunnerRegistry &);
+
 private:
     Ipc::FewToFewBiQueue::Owner *owner;
 };
@@ -846,16 +848,17 @@ private:
 RunnerRegistrationEntry(rrAfterConfig, IpcIoRr);
 
 
-void IpcIoRr::run(const RunnerRegistry &)
+void IpcIoRr::create(const RunnerRegistry &)
 {
     if (!UsingSmp())
         return;
 
-    if (IamMasterProcess()) {
-        Must(!owner);
-        // XXX: make capacity configurable
-        owner = Ipc::FewToFewBiQueue::Init(ShmLabel, Config.workers, 1, Config.cacheSwap.n_configured, 1 + Config.workers, sizeof(IpcIoMsg), 1024);
-    }
+    Must(!owner);
+    // XXX: make capacity configurable
+    owner = Ipc::FewToFewBiQueue::Init(ShmLabel, Config.workers, 1,
+                                       Config.cacheSwap.n_configured,
+                                       1 + Config.workers, sizeof(IpcIoMsg),
+                                       1024);
 }
 
 IpcIoRr::~IpcIoRr()
index 4fa55755eef2582f0ddfcd3afe142bc6702421ac..aece4239369de68cb63735c10e2a21207d73ecc7 100644 (file)
@@ -343,7 +343,7 @@ MemStore::EntryLimit()
 
 
 /// initializes shared memory segments used by MemStore
-class MemStoreRr: public RegisteredRunner
+class MemStoreRr: public Ipc::Mem::RegisteredRunner
 {
 public:
     /* RegisteredRunner API */
@@ -351,6 +351,9 @@ public:
     virtual void run(const RunnerRegistry &);
     virtual ~MemStoreRr();
 
+protected:
+    virtual void create(const RunnerRegistry &);
+
 private:
     MemStoreMap::Owner *owner;
 };
@@ -358,7 +361,7 @@ private:
 RunnerRegistrationEntry(rrAfterConfig, MemStoreRr);
 
 
-void MemStoreRr::run(const RunnerRegistry &)
+void MemStoreRr::run(const RunnerRegistry &r)
 {
     // decide whether to use a shared memory cache if the user did not specify
     if (!Config.memShared.configured()) {
@@ -375,16 +378,19 @@ void MemStoreRr::run(const RunnerRegistry &)
                " a single worker is running");
     }
 
+    Ipc::Mem::RegisteredRunner::run(r);
+}
+
+void MemStoreRr::create(const RunnerRegistry &)
+{
     if (!Config.memShared)
         return;
 
-    if (IamMasterProcess()) {
-        Must(!owner);
-        const int64_t entryLimit = MemStore::EntryLimit();
-        if (entryLimit <= 0)
-            return; // no memory cache configured or a misconfiguration
-        owner = MemStoreMap::Init(ShmLabel, entryLimit);
-    }
+    Must(!owner);
+    const int64_t entryLimit = MemStore::EntryLimit();
+    if (entryLimit <= 0)
+        return; // no memory cache configured or a misconfiguration
+    owner = MemStoreMap::Init(ShmLabel, entryLimit);
 }
 
 MemStoreRr::~MemStoreRr()
index e809ad4ba8d44c814dad86667e920e791792e2a9..2c18b0d0428ba522e1b0e62840999215f33fde40 100644 (file)
@@ -810,13 +810,15 @@ Rock::SwapDir::statfs(StoreEntry &e) const
 
 
 /// initializes shared memory segments used by Rock::SwapDir
-class RockSwapDirRr: public RegisteredRunner
+class RockSwapDirRr: public Ipc::Mem::RegisteredRunner
 {
 public:
     /* RegisteredRunner API */
-    virtual void run(const RunnerRegistry &);
     virtual ~RockSwapDirRr();
 
+protected:
+    virtual void create(const RunnerRegistry &);
+
 private:
     Vector<Rock::SwapDir::DirMap::Owner *> owners;
 };
@@ -824,16 +826,15 @@ private:
 RunnerRegistrationEntry(rrAfterConfig, RockSwapDirRr);
 
 
-void RockSwapDirRr::run(const RunnerRegistry &)
+void RockSwapDirRr::create(const RunnerRegistry &)
 {
-    if (IamMasterProcess()) {
-        Must(owners.empty());
-        for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
-            if (const Rock::SwapDir *const sd = dynamic_cast<Rock::SwapDir *>(INDEXSD(i))) {
-                // TODO: check whether entryLimitAllowed() has map here
-                Rock::SwapDir::DirMap::Owner *const owner = Rock::SwapDir::DirMap::Init(sd->path, sd->entryLimitAllowed());
-                owners.push_back(owner);
-            }
+    Must(owners.empty());
+    for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+        if (const Rock::SwapDir *const sd = dynamic_cast<Rock::SwapDir *>(INDEXSD(i))) {
+            // TODO: check whether entryLimitAllowed() has map here
+            Rock::SwapDir::DirMap::Owner *const owner =
+                Rock::SwapDir::DirMap::Init(sd->path, sd->entryLimitAllowed());
+            owners.push_back(owner);
         }
     }
 }
index deecbf90792ed518cc82a76fbb461a8362f23f65..054938bf8cc842df7299e706782ca3ada067f6e0 100644 (file)
@@ -85,12 +85,14 @@ Ipc::Mem::PageLevel(const int purpose)
 }
 
 /// initializes shared memory pages
-class SharedMemPagesRr: public RegisteredRunner
+class SharedMemPagesRr: public Ipc::Mem::RegisteredRunner
 {
 public:
     /* RegisteredRunner API */
     SharedMemPagesRr(): owner(NULL) {}
     virtual void run(const RunnerRegistry &);
+    virtual void create(const RunnerRegistry &);
+    virtual void open(const RunnerRegistry &);
     virtual ~SharedMemPagesRr();
 
 private:
@@ -100,7 +102,8 @@ private:
 RunnerRegistrationEntry(rrAfterConfig, SharedMemPagesRr);
 
 
-void SharedMemPagesRr::run(const RunnerRegistry &)
+void
+SharedMemPagesRr::run(const RunnerRegistry &r)
 {
     if (!UsingSmp())
         return;
@@ -119,11 +122,20 @@ void SharedMemPagesRr::run(const RunnerRegistry &)
         return;
     }
 
-    if (IamMasterProcess()) {
-        Must(!owner);
-        owner = Ipc::Mem::PagePool::Init(PagePoolId, Ipc::Mem::PageLimit(), Ipc::Mem::PageSize());
-    }
+    Ipc::Mem::RegisteredRunner::run(r);
+}
 
+void
+SharedMemPagesRr::create(const RunnerRegistry &)
+{
+    Must(!owner);
+    owner = Ipc::Mem::PagePool::Init(PagePoolId, Ipc::Mem::PageLimit(),
+                                     Ipc::Mem::PageSize());
+}
+
+void
+SharedMemPagesRr::open(const RunnerRegistry &)
+{
     Must(!ThePagePool);
     ThePagePool = new Ipc::Mem::PagePool(PagePoolId);
 }