From 7f7b35accef9d2e5165be7bb451c57b9f6f3e557 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 31 Jan 2017 14:43:50 +0100 Subject: [PATCH] Faster reloading of stats pages --- lib/shared_memory.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index a61ddb2b..aef4f172 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -942,7 +942,7 @@ namespace IPC { VERYHIGH_MSG("Shared memory %s is now at count %u", baseName.c_str(), amount); } uint32_t tmpPID = *((uint32_t *)(it->mapped + 1 + offset + payLen - 4)); - if (tmpPID > 1 && !Util::Procs::isRunning(tmpPID) && !(countNum == 126 || countNum == 127)){ + if (tmpPID > 1 && it->master && !Util::Procs::isRunning(tmpPID) && !(countNum == 126 || countNum == 127)){ WARN_MSG("process disappeared, timing out. (pid %lu)", tmpPID); *counter = 125 | (0x80 & (*counter)); //if process is already dead, instant timeout. } @@ -956,7 +956,7 @@ namespace IPC { break; default: #ifndef NOCRASHCHECK - if (tmpPID > 1) { + if (tmpPID > 1 && it->master) { if (countNum > 10 && countNum < 60) { if (countNum < 30) { if (countNum > 15) { @@ -1038,15 +1038,22 @@ namespace IPC { ++emptyCount; } else { emptyCount = 0; + std::deque::iterator tIt = it; + if (++tIt == myPages.end()){ + bool unsetMaster = !(it->master); + semGuard tmpGuard(&mySemaphore); + newPage(); + if (unsetMaster){ + (myPages.end()-1)->master = false; + } + it = myPages.end() - 2; + } } } if (emptyCount > 1) { semGuard tmpGuard(&mySemaphore); deletePage(); - } else if (!emptyCount) { - semGuard tmpGuard(&mySemaphore); - newPage(); } if (empty) {