[PATCH 6/9] Rewrite shared memory registry runners using Ipc::Mem::RegisteredRunner.

From: Dmitry Kurochkin <dmitry.kurochkin_at_measurement-factory.com>
Date: Thu, 29 Sep 2011 03:06:04 +0400

This allows simpler code and cleaner separation between shared segment
creation and openning.

---
 src/DiskIO/IpcIo/IpcIoFile.cc |   19 +++++++++++--------
 src/MemStore.cc               |   24 +++++++++++++++---------
 src/fs/rock/RockSwapDir.cc    |   23 ++++++++++++-----------
 src/ipc/mem/Pages.cc          |   24 ++++++++++++++++++------
 4 files changed, 56 insertions(+), 34 deletions(-)
diff --git src/DiskIO/IpcIo/IpcIoFile.cc src/DiskIO/IpcIo/IpcIoFile.cc
index 9c59c11..13c0d00 100644
--- src/DiskIO/IpcIo/IpcIoFile.cc
+++ src/DiskIO/IpcIo/IpcIoFile.cc
@@ -767,14 +767,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;
 };
@@ -782,16 +784,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()
diff --git src/MemStore.cc src/MemStore.cc
index 4fa5575..aece423 100644
--- src/MemStore.cc
+++ src/MemStore.cc
@@ -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()
diff --git src/fs/rock/RockSwapDir.cc src/fs/rock/RockSwapDir.cc
index 8b17ec3..d500ce4 100644
--- src/fs/rock/RockSwapDir.cc
+++ src/fs/rock/RockSwapDir.cc
@@ -766,13 +766,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;
 };
@@ -780,16 +782,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);
         }
     }
 }
diff --git src/ipc/mem/Pages.cc src/ipc/mem/Pages.cc
index deecbf9..054938b 100644
--- src/ipc/mem/Pages.cc
+++ src/ipc/mem/Pages.cc
@@ -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);
 }
-- 
1.7.6.3
Received on Wed Sep 28 2011 - 23:07:19 MDT

This archive was generated by hypermail 2.2.0 : Thu Sep 29 2011 - 12:00:03 MDT