aivika-transformers-5.3: Transformers for the Aivika simulation library

CopyrightCopyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Simulation.Aivika.Trans.Resource.Preemption

Description

Tested with: GHC 8.0.1

This module defines the preemptible resource.

Synopsis

Documentation

class MonadDES m => MonadResource m where Source #

A type class of monads whithin which we can create preemptible resources.

Associated Types

data Resource m Source #

Represents a preemptible resource.

Methods

newResource :: Int -> Event m (Resource m) Source #

Create a new resource with the specified initial count that becomes the upper bound as well.

newResourceWithMaxCount :: Int -> Maybe Int -> Event m (Resource m) Source #

Create a new resource with the specified initial and maximum counts, where Nothing means that the resource has no upper bound.

resourceCount :: Resource m -> Event m Int Source #

Return the current count of the resource.

resourceMaxCount :: Resource m -> Maybe Int Source #

Return the maximum count of the resource, where Nothing means that the resource has no upper bound.

resourceCountStats :: Resource m -> Event m (TimingStats Int) Source #

Return the statistics for the available count of the resource.

resourceCountChanged :: Resource m -> Signal m Int Source #

Signal triggered when the resourceCount property changes.

resourceCountChanged_ :: Resource m -> Signal m () Source #

Signal triggered when the resourceCount property changes.

resourceUtilisationCount :: Resource m -> Event m Int Source #

Return the current utilisation count of the resource.

resourceUtilisationCountStats :: Resource m -> Event m (TimingStats Int) Source #

Return the statistics for the utilisation count of the resource.

resourceUtilisationCountChanged :: Resource m -> Signal m Int Source #

Signal triggered when the resourceUtilisationCount property changes.

resourceUtilisationCountChanged_ :: Resource m -> Signal m () Source #

Signal triggered when the resourceUtilisationCount property changes.

resourceQueueCount :: Resource m -> Event m Int Source #

Return the current queue length of the resource.

resourceQueueCountStats :: Resource m -> Event m (TimingStats Int) Source #

Return the statistics for the queue length of the resource.

resourceQueueCountChanged :: Resource m -> Signal m Int Source #

Signal triggered when the resourceQueueCount property changes.

resourceQueueCountChanged_ :: Resource m -> Signal m () Source #

Signal triggered when the resourceQueueCount property changes.

resourceTotalWaitTime :: Resource m -> Event m Double Source #

Return the total wait time of the resource.

resourceWaitTime :: Resource m -> Event m (SamplingStats Double) Source #

Return the statistics for the wait time of the resource.

resourceWaitTimeChanged :: Resource m -> Signal m (SamplingStats Double) Source #

Signal triggered when the resourceTotalWaitTime and resourceWaitTime properties change.

resourceWaitTimeChanged_ :: Resource m -> Signal m () Source #

Signal triggered when the resourceTotalWaitTime and resourceWaitTime properties change.

resourceChanged_ :: Resource m -> Signal m () Source #

Signal triggered when one of the resource counters changes.

requestResourceWithPriority :: Resource m -> Double -> Process m () Source #

Request with the priority for the resource decreasing its count in case of success, otherwise suspending the discontinuous process until some other process releases the resource.

It may preempt another process if the latter aquired the resource before but had a lower priority. Then the current process takes an ownership of the resource.

releaseResource :: Resource m -> Process m () Source #

Release the resource increasing its count and resuming one of the previously suspended or preempted processes as possible.

usingResourceWithPriority :: Resource m -> Double -> Process m a -> Process m a Source #

Acquire the resource with the specified priority, perform some action and safely release the resource in the end, even if the IOException was raised within the action.

incResourceCount :: Resource m -> Int -> Event m () Source #

Increase the count of available resource by the specified number, invoking the awaiting and preempted processes according to their priorities as needed.

decResourceCount :: Resource m -> Int -> Event m () Source #

Decrease the count of available resource by the specified number, preempting the processes according to their priorities as needed.

alterResourceCount :: Resource m -> Int -> Event m () Source #

Alter the resource count either increasing or decreasing it by calling incResourceCount or decResourceCount respectively.

resetResource :: Resource m -> Event m () Source #

Reset the statistics.