Added sharedServer abandon() function, changed sharedServer.myPages container from set to deque

This commit is contained in:
Thulinma 2016-09-21 23:05:27 +02:00
parent 9e9e5685b4
commit cdab043a4b
2 changed files with 17 additions and 6 deletions

View file

@ -790,10 +790,20 @@ namespace IPC {
return myPages.size(); return myPages.size();
} }
///Sets all currently loaded memory pages to non-master, so they are not cleaned up on destruction, but left behind.
///Useful for doing rolling updates and such.
void sharedServer::abandon(){
if (!myPages.size()){return;}
VERYHIGH_MSG("Abandoning %llu memory pages, leaving them behind on purpose", myPages.size());
for (std::deque<sharedPage>::iterator it = myPages.begin(); it != myPages.end(); it++) {
(*it).master = false;
}
}
///\brief Creates the next page with the correct size ///\brief Creates the next page with the correct size
void sharedServer::newPage() { void sharedServer::newPage() {
sharedPage tmp(std::string(baseName.substr(1) + (char)(myPages.size() + (int)'A')), std::min(((8192 * 2) << myPages.size()), (32 * 1024 * 1024)), true); sharedPage tmp(std::string(baseName.substr(1) + (char)(myPages.size() + (int)'A')), std::min(((8192 * 2) << myPages.size()), (32 * 1024 * 1024)), true);
myPages.insert(tmp); myPages.push_back(tmp);
tmp.master = false; tmp.master = false;
DEBUG_MSG(DLVL_VERYHIGH, "Created a new page: %s", tmp.name.c_str()); DEBUG_MSG(DLVL_VERYHIGH, "Created a new page: %s", tmp.name.c_str());
} }
@ -804,13 +814,13 @@ namespace IPC {
DEBUG_MSG(DLVL_WARN, "Can't remove last page for %s", baseName.c_str()); DEBUG_MSG(DLVL_WARN, "Can't remove last page for %s", baseName.c_str());
return; return;
} }
myPages.erase((*myPages.rbegin())); myPages.pop_back();
} }
///\brief Determines whether an id is currently in use or not ///\brief Determines whether an id is currently in use or not
bool sharedServer::isInUse(unsigned int id) { bool sharedServer::isInUse(unsigned int id) {
unsigned int i = 0; unsigned int i = 0;
for (std::set<sharedPage>::iterator it = myPages.begin(); it != myPages.end(); it++) { for (std::deque<sharedPage>::iterator it = myPages.begin(); it != myPages.end(); it++) {
//return if we reached the end //return if we reached the end
if (!it->mapped || !it->len) { if (!it->mapped || !it->len) {
return false; return false;
@ -859,7 +869,7 @@ namespace IPC {
} }
semGuard tmpGuard(&mySemaphore); semGuard tmpGuard(&mySemaphore);
unsigned int id = 0; unsigned int id = 0;
for (std::set<sharedPage>::iterator it = myPages.begin(); it != myPages.end(); it++) { for (std::deque<sharedPage>::iterator it = myPages.begin(); it != myPages.end(); it++) {
if (!it->mapped || !it->len) { if (!it->mapped || !it->len) {
DEBUG_MSG(DLVL_FAIL, "Something went terribly wrong?"); DEBUG_MSG(DLVL_FAIL, "Something went terribly wrong?");
return 0; return 0;
@ -900,7 +910,7 @@ namespace IPC {
unsigned int userCount = 0; unsigned int userCount = 0;
unsigned int emptyCount = 0; unsigned int emptyCount = 0;
connectedUsers = 0; connectedUsers = 0;
for (std::set<sharedPage>::iterator it = myPages.begin(); it != myPages.end(); it++) { for (std::deque<sharedPage>::iterator it = myPages.begin(); it != myPages.end(); it++) {
if (!it->mapped || !it->len) { if (!it->mapped || !it->len) {
DEBUG_MSG(DLVL_FAIL, "Something went terribly wrong?"); DEBUG_MSG(DLVL_FAIL, "Something went terribly wrong?");
break; break;

View file

@ -187,6 +187,7 @@ namespace IPC {
unsigned int amount; unsigned int amount;
unsigned int connectedUsers; unsigned int connectedUsers;
void finishEach(); void finishEach();
void abandon();
private: private:
bool isInUse(unsigned int id); bool isInUse(unsigned int id);
void newPage(); void newPage();
@ -196,7 +197,7 @@ namespace IPC {
///\brief The length of each consecutive piece of payload ///\brief The length of each consecutive piece of payload
unsigned int payLen; unsigned int payLen;
///\brief The set of sharedPage structures to manage the actual memory ///\brief The set of sharedPage structures to manage the actual memory
std::set<sharedPage> myPages; std::deque<sharedPage> myPages;
///\brief A semaphore that is locked upon creation and deletion of the page, to ensure no new data is allocated during this step. ///\brief A semaphore that is locked upon creation and deletion of the page, to ensure no new data is allocated during this step.
semaphore mySemaphore; semaphore mySemaphore;
///\brief Whether the payload has a counter, if so, it is added in front of the payload ///\brief Whether the payload has a counter, if so, it is added in front of the payload