Check if memory locking should be done before locking unconditionally

This commit is contained in:
Daniel J. Hofmann 2015-10-13 16:12:29 +02:00 committed by Patrick Niklaus
parent 993321e971
commit 78283a0e0e

View File

@ -93,7 +93,7 @@ int main(int argc, const char *argv[]) try
{ {
explicit MemoryLocker(bool shouldLock_) : shouldLock(shouldLock_) explicit MemoryLocker(bool shouldLock_) : shouldLock(shouldLock_)
{ {
if (-1 == mlockall(MCL_CURRENT | MCL_FUTURE)) if (shouldLock && -1 == mlockall(MCL_CURRENT | MCL_FUTURE))
{ {
couldLock = false; couldLock = false;
SimpleLogger().Write(logWARNING) << "memory could not be locked to RAM"; SimpleLogger().Write(logWARNING) << "memory could not be locked to RAM";
@ -101,7 +101,7 @@ int main(int argc, const char *argv[]) try
} }
~MemoryLocker() ~MemoryLocker()
{ {
if (couldLock) if (shouldLock && couldLock)
(void)munlockall(); (void)munlockall();
} }
bool shouldLock = false, couldLock = true; bool shouldLock = false, couldLock = true;