Stability | experimental |
---|---|
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Safe Haskell | Safe-Inferred |
Tested with: GHC 7.6.3
This module defines a limited resource which can be acquired and
then released by the discontinuous process Process
.
- data Resource
- newResource :: EventQueue -> Int -> Simulation Resource
- newResourceWithCount :: EventQueue -> Int -> Int -> Simulation Resource
- resourceQueue :: Resource -> EventQueue
- resourceInitCount :: Resource -> Int
- resourceCount :: Resource -> Dynamics Int
- requestResource :: Resource -> Process ()
- tryRequestResourceInDynamics :: Resource -> Dynamics Bool
- releaseResource :: Resource -> Process ()
- releaseResourceInDynamics :: Resource -> Dynamics ()
- usingResource :: Resource -> Process a -> Process a
Documentation
newResource :: EventQueue -> Int -> Simulation ResourceSource
Create a new resource with the specified initial count.
newResourceWithCount :: EventQueue -> Int -> Int -> Simulation ResourceSource
Create a new resource with the specified initial count. The third argument specifies how the resource is consumed at the beginning, i.e. it defines the current count, which must be non-negative and less or equal to the initial count.
resourceQueue :: Resource -> EventQueueSource
Return the bound event queue.
resourceInitCount :: Resource -> IntSource
Return the initial count of the resource.
resourceCount :: Resource -> Dynamics IntSource
Return the current count of the resource.
requestResource :: Resource -> Process ()Source
Request for the resource decreasing its count in case of success, otherwise suspending the discontinuous process until some other process releases the resource.
releaseResource :: Resource -> Process ()Source
Release the resource increasing its count and resuming one of the previously suspended processes as possible.
releaseResourceInDynamics :: Resource -> Dynamics ()Source
Release the resource increasing its count and resuming one of the previously suspended processes as possible.
usingResource :: Resource -> Process a -> Process aSource
Acquire the resource, perform some action and safely release the resource
in the end, even if the IOException
was raised within the action.
The process identifier must be created with support of exception
handling, i.e. with help of function newProcessIDWithCatch
. Unfortunately,
such processes are slower than those that are created with help of
other function newProcessID
.