aivika-0.5.1: A multi-paradigm simulation library

Stabilityexperimental
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Safe HaskellSafe-Inferred

Simulation.Aivika.Dynamics.Resource

Description

Tested with: GHC 7.0.3

This module defines a limited resource which can be acquired and then released by the discontinuous process Process.

Synopsis

Documentation

data Resource Source

Represents a limited resource.

Instances

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.

tryRequestResourceInDynamics :: Resource -> Dynamics BoolSource

Try to request for the resource decreasing its count in case of success and returning True in the Dynamics monad; otherwise, returning False.

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.