From: Dmitry Kurochkin Date: Tue, 4 Oct 2011 17:27:22 +0000 (+0400) Subject: Rewrite shared memory registry runners using Ipc::Mem::RegisteredRunner. X-Git-Tag: BumpSslServerFirst.take01~122^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4404f1c5417348fcc89ae99c7b00a87a74530fa0;p=thirdparty%2Fsquid.git Rewrite shared memory registry runners using Ipc::Mem::RegisteredRunner. This allows simpler code and cleaner separation between shared segment creation and openning. --- diff --git a/src/DiskIO/IpcIo/IpcIoFile.cc b/src/DiskIO/IpcIo/IpcIoFile.cc index 6b3e8ddcbd..a00a8035ce 100644 --- a/src/DiskIO/IpcIo/IpcIoFile.cc +++ b/src/DiskIO/IpcIo/IpcIoFile.cc @@ -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() diff --git a/src/MemStore.cc b/src/MemStore.cc index 4fa55755ee..aece423936 100644 --- a/src/MemStore.cc +++ b/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 a/src/fs/rock/RockSwapDir.cc b/src/fs/rock/RockSwapDir.cc index e809ad4ba8..2c18b0d042 100644 --- a/src/fs/rock/RockSwapDir.cc +++ b/src/fs/rock/RockSwapDir.cc @@ -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 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(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(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 a/src/ipc/mem/Pages.cc b/src/ipc/mem/Pages.cc index deecbf9079..054938bf8c 100644 --- a/src/ipc/mem/Pages.cc +++ b/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); }