priority-sync-0.1.0.1: Cooperative task prioritization.Source codeContentsIndex
Control.Concurrent.Priority.Room
Synopsis
data Room u
newRoom :: u -> IO (Room u)
inUse :: Room u -> STM (Set ThreadId)
data Claim u
claimedRoom :: Claim u -> Room u
claimedThread :: Claim u -> ThreadId
userData :: Room u -> u
type family UserData u :: *
class RoomGroup m where
roomsOf :: m -> [Room (UserData m)]
class RoomConstraint u where
approveConstraint :: Claim a -> u -> STM ()
class BaseRoomContext c where
type BaseRoomContextData c :: *
approveClaimsEntering :: c -> [Claim (UserData c)] -> STM (BaseRoomContextData c)
approveClaimsExiting :: c -> [Claim (UserData c)] -> STM (BaseRoomContextData c)
waitingAction :: c -> BaseRoomContextData c -> STM ()
class RoomContext c where
type Base c :: *
baseContext :: c -> Base c
newtype MaxThreads = MaxThreads Int
data ClaimMode
= Acquire
| Release
data DefaultRoomContext u = Default
data UnconstrainedRoomContext u = Unconstrained
claim :: (RoomGroup c, RoomContext c, BaseRoomContext (Base c), UserData c ~ UserData (Base c)) => ClaimMode -> c -> IO a -> IO a
approveClaims :: RoomConstraint u => [Claim u] -> STM ()
Documentation
data Room u Source
A resource pool, parameterized against arbitrary user data.
show/hide Instances
newRoom :: u -> IO (Room u)Source
Create a new Room with some arbitrary user data.
inUse :: Room u -> STM (Set ThreadId)Source
Get all ThreadIds that are currently claimimg this Room.
data Claim u Source
A Claim, or attempt to acquire or release a Room.
claimedRoom :: Claim u -> Room uSource
Get the Room target of a Claim.
claimedThread :: Claim u -> ThreadIdSource
Get the thread attempting a Claim.
userData :: Room u -> uSource
Get the user data associated with a Room.
type family UserData u :: *Source
class RoomGroup m whereSource
Methods
roomsOf :: m -> [Room (UserData m)]Source
show/hide Instances
class RoomConstraint u whereSource
Methods
approveConstraint :: Claim a -> u -> STM ()Source
Should either approve or retry each claim.
show/hide Instances
class BaseRoomContext c whereSource
Rules for calling claim_. The two major contexts are DefaultRoomContext, which uses RoomConstraints to determine which Rooms are available, and UnconstrainedRoomContext, which does not place any constraints on any Room.
Associated Types
type BaseRoomContextData c :: *Source
Methods
approveClaimsEntering :: c -> [Claim (UserData c)] -> STM (BaseRoomContextData c)Source
Should approve a some claims before entering a critical section, as described by claim_.
approveClaimsExiting :: c -> [Claim (UserData c)] -> STM (BaseRoomContextData c)Source
Should approve a some claims before exiting a critical section, as described by claim_.
waitingAction :: c -> BaseRoomContextData c -> STM ()Source
A waiting transaction, as described by claim_.
show/hide Instances
class RoomContext c whereSource
An indirect reference to a BaseRoomContext.
Associated Types
type Base c :: *Source
Methods
baseContext :: c -> Base cSource
show/hide Instances
newtype MaxThreads Source
A maximum limit on the number of threads allowed to claim a room.
Constructors
MaxThreads Int
show/hide Instances
data ClaimMode Source
Constructors
Acquire
Release
show/hide Instances
data DefaultRoomContext u Source
Require that all RoomConstraints be satisfied when acquiring a Room. This is the default.
Constructors
Default
show/hide Instances
data UnconstrainedRoomContext u Source
Don't check any RoomConstraints when acquiring a Room.
Constructors
Unconstrained
show/hide Instances
claim :: (RoomGroup c, RoomContext c, BaseRoomContext (Base c), UserData c ~ UserData (Base c)) => ClaimMode -> c -> IO a -> IO aSource

Temporarily Acquire, and then release, or Release, and then acquire, some Rooms for the duration of a critical section. A simple example where a room might be used to prevent interleaving of stdout:

 room <- newRoom (MaxThreads 1)
 forkIO $ claim Acquire room $ putStrLn "Hello World!"
 forkIO $ claim Acquire room $ putStrLn "Foo!  Bar!"
approveClaims :: RoomConstraint u => [Claim u] -> STM ()Source
approve some claims according to their constraints.
Produced by Haddock version 2.4.2