module System.Posix.Realtime.RTSched (
Pid,
Policy,
SchedParam(..),
schedYield,
schedGetScheduler,
schedSetScheduler,
schedGetParam,
schedSetParam,
schedGetPriorityMin,
schedGetPriorityMax,
schedRRGetInterval
) where
import System.IO
import System.IO.Error
import System.Posix.Realtime.RTDataTypes
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
type Pid = Int
type Policy = Int
data SchedParam = SchedParam {schedPriority :: Int}
instance Storable SchedParam where
sizeOf (SchedParam schedPriority) = (4)
alignment _ = 1
poke p_schedParam (SchedParam schedPriority) =
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p_schedParam schedPriority
peek p_schedParam = do
schedPriority <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p_schedParam
return (SchedParam schedPriority)
schedYield :: IO ()
schedYield = do
throwErrnoIfMinus1 "schedYield" (c_sched_yield)
return ()
foreign import ccall unsafe "sched.h sched_yield"
c_sched_yield :: IO CInt
schedGetScheduler :: Pid -> IO (Int)
schedGetScheduler pid = do
rc <- throwErrnoIfMinus1 "schedGetScheduler" (c_sched_getscheduler (fromIntegral pid))
return (fromIntegral rc)
foreign import ccall unsafe "sched.h sched_getscheduler"
c_sched_getscheduler :: CInt -> IO CInt
schedSetScheduler :: Pid -> Policy -> SchedParam -> IO ()
schedSetScheduler pid policy param = do
allocaBytes (4) $ \ p_schedParam -> do
poke p_schedParam param
throwErrnoIfMinus1 "schedSetScheduler" (c_sched_setscheduler (fromIntegral pid)
(fromIntegral policy) p_schedParam)
return ()
foreign import ccall unsafe "sched.h sched_setscheduler"
c_sched_setscheduler :: CInt -> CInt -> Ptr SchedParam -> IO CInt
schedGetParam :: Pid -> IO SchedParam
schedGetParam pid = do
allocaBytes (4) $ \ p_schedParam -> do
throwErrnoIfMinus1 "schedGetParam" (c_sched_getparam (fromIntegral pid) p_schedParam)
schedParam <- peek p_schedParam
return (schedParam)
foreign import ccall unsafe "sched.h sched_getparam"
c_sched_getparam :: CInt -> Ptr SchedParam -> IO CInt
schedSetParam :: Pid -> SchedParam -> IO ()
schedSetParam pid param = do
allocaBytes (4) $ \ p_schedParam -> do
poke p_schedParam param
throwErrnoIfMinus1 "schedSetParam" (c_sched_setparam (fromIntegral pid) p_schedParam)
return ()
foreign import ccall unsafe "sched.h sched_setparam"
c_sched_setparam :: CInt -> Ptr SchedParam -> IO CInt
schedGetPriorityMin :: Policy -> IO (Int)
schedGetPriorityMin policy = do
rc <- throwErrnoIfMinus1 "schedGetPriorityMin" (c_sched_get_priority_min (fromIntegral policy))
return (fromIntegral rc)
foreign import ccall unsafe "sched.h sched_get_priority_min"
c_sched_get_priority_min :: CInt -> IO CInt
schedGetPriorityMax :: Policy -> IO (Int)
schedGetPriorityMax policy = do
rc <- throwErrnoIfMinus1 "schedGetPriorityMax" (c_sched_get_priority_max (fromIntegral policy))
return (fromIntegral rc)
foreign import ccall unsafe "sched.h sched_get_priority_max"
c_sched_get_priority_max :: CInt -> IO CInt
schedRRGetInterval :: Pid -> IO (TimeSpec)
schedRRGetInterval pid = do
allocaBytes (16) $ \ p_timeSpec -> do
throwErrnoIfMinus1 "schedRRGetInterval" (c_sched_rr_get_interval (fromIntegral pid) p_timeSpec)
timeSpec <- peek p_timeSpec
return (timeSpec)
foreign import ccall unsafe "sched.h sched_rr_get_interval"
c_sched_rr_get_interval :: CInt -> Ptr TimeSpec -> IO CInt