MemLocker.cpp (1364B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 MemLocker.cpp - Memory page locker 5 Copyright (C) 2019-2019 Johannes Lorenz 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of version 2 of the GNU General Public License 9 as published by the Free Software Foundation. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License (version 2 or later) for more details. 15 16 You should have received a copy of the GNU General Public License (version 2) 17 along with this program; if not, write to the Free Software Foundation, 18 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 20 */ 21 22 #include "MemLocker.h" 23 24 #ifndef WIN32 25 #include <cstdio> 26 #include <sys/mman.h> 27 #endif 28 29 namespace zyn { 30 31 void MemLocker::lock() 32 { 33 #ifndef WIN32 34 if (!isLocked) 35 { 36 if (mlockall (MCL_CURRENT | MCL_FUTURE)) { 37 perror ("Warning: Can not lock memory"); 38 } else { 39 isLocked = true; 40 } 41 } 42 #endif 43 } 44 45 void MemLocker::unlock() 46 { 47 #ifndef WIN32 48 if (isLocked) 49 { 50 if (munlockall ()) { 51 perror ("Warning: Can not unlock memory"); 52 } else { 53 isLocked = false; 54 } 55 } 56 #endif 57 } 58 59 }