Copyright | Copyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Tested with: GHC 8.0.1
This module defines the preemptible resource.
The module is optimised in the sense that this kind of the resource has neither additional signals, nor counters that would may slow down the simulation.
Synopsis
- class MonadDES m => MonadResource m where
- data Resource m
- newResource :: Int -> Simulation m (Resource m)
- newResourceWithMaxCount :: Int -> Maybe Int -> Simulation m (Resource m)
- resourceCount :: Resource m -> Event m Int
- resourceMaxCount :: Resource m -> Maybe Int
- requestResourceWithPriority :: Resource m -> Double -> Process m ()
- releaseResource :: Resource m -> Process m ()
- usingResourceWithPriority :: Resource m -> Double -> Process m a -> Process m a
- incResourceCount :: Resource m -> Int -> Event m ()
- decResourceCount :: Resource m -> Int -> Event m ()
- alterResourceCount :: Resource m -> Int -> Event m ()
Documentation
class MonadDES m => MonadResource m where Source #
A type class of monads whithin which we can create preemptible resources.
:: Int | the initial count (and maximal count too) of the resource |
-> Simulation m (Resource m) |
Create a new resource with the specified initial count that becomes the upper bound as well.
newResourceWithMaxCount Source #
:: Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation m (Resource m) |
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.
requestResourceWithPriority Source #
:: Resource m | the requested resource |
-> Double | the priority (the less value has a higher priority) |
-> Process m () |
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.
Release the resource increasing its count and resuming one of the previously suspended or preempted processes as possible.
usingResourceWithPriority Source #
:: Resource m | the resource we are going to request for and then release in the end |
-> Double | the priority (the less value has a higher priority) |
-> Process m a | the action we are going to apply having the resource |
-> Process m a | the result of the action |
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.
Increase the count of available resource by the specified number, invoking the awaiting and preempted processes according to their priorities as needed.
Decrease the count of available resource by the specified number, preempting the processes according to their priorities as needed.
Alter the resource count either increasing or decreasing it by calling
incResourceCount
or decResourceCount
respectively.
Instances
MonadResource IO Source # | The |
Defined in Simulation.Aivika.IO.Resource.Preemption.Base newResource :: Int -> Simulation IO (Resource IO) Source # newResourceWithMaxCount :: Int -> Maybe Int -> Simulation IO (Resource IO) Source # resourceCount :: Resource IO -> Event IO Int Source # resourceMaxCount :: Resource IO -> Maybe Int Source # requestResourceWithPriority :: Resource IO -> Double -> Process IO () Source # releaseResource :: Resource IO -> Process IO () Source # usingResourceWithPriority :: Resource IO -> Double -> Process IO a -> Process IO a Source # incResourceCount :: Resource IO -> Int -> Event IO () Source # decResourceCount :: Resource IO -> Int -> Event IO () Source # alterResourceCount :: Resource IO -> Int -> Event IO () Source # |