module System.Posix.Realtime.LockedMem (
LockAllFlags(..),
lockMemory,
unlockMemory,
lockAllMemory,
unlockAllMemory
) where
import System.IO
import System.IO.Error
import System.Posix.Types
import System.Posix.Error
import System.Posix.Internals
import Foreign
import Foreign.C
import Data.Bits
import GHC.IO
import GHC.IO.Handle hiding (fdToHandle)
import qualified GHC.IO.Handle
data LockAllFlags = CURRENT | FUTURE
lockMemory :: Ptr Word8 -> ByteCount -> IO ()
lockMemory mem len = do
throwErrnoIfMinus1 "lockMemory" (c_mlock mem len)
return ()
foreign import ccall unsafe "sys/mman.h mlock"
c_mlock :: Ptr Word8 -> CSize -> IO CInt
unlockMemory :: Ptr Word8 -> ByteCount -> IO ()
unlockMemory mem len = do
throwErrnoIfMinus1 "lockMemory" (c_mlock mem len)
return ()
foreign import ccall unsafe "sys/mman.h mlock"
c_munlock :: Ptr Word8 -> CSize -> IO CInt
lockAllMemory :: LockAllFlags -> IO ()
lockAllMemory flags = do
throwErrnoIfMinus1 "lockAllMemory" (c_mlockall cflags)
return ()
where
cflags = case flags of
CURRENT -> (1)
FUTURE -> (2)
foreign import ccall unsafe "sys/mman.h mlockall"
c_mlockall :: CInt -> IO CInt
unlockAllMemory :: IO ()
unlockAllMemory = do
throwErrnoIfMinus1 "unlockAllMemory" c_munlockall
return ()
foreign import ccall unsafe "sys/mman.h munlockall"
c_munlockall :: IO CInt