Copyright | Copyright (c) 2009-2014, David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Tested with: GHC 7.8.3
This module defines the resource which can be acquired and
then released by the discontinuous process Process
.
The resource can be either limited by the upper bound
(run-time check), or it can have no upper bound. The latter
is useful for modeling the infinite queue, for example.
- type FCFSResource m = Resource m FCFS
- type LCFSResource m = Resource m LCFS
- type SIROResource m = Resource m SIRO
- type PriorityResource m = Resource m StaticPriorities
- data Resource m s
- newFCFSResource :: MonadComp m => Int -> Simulation m (FCFSResource m)
- newFCFSResourceWithMaxCount :: MonadComp m => Int -> Maybe Int -> Simulation m (FCFSResource m)
- newLCFSResource :: MonadComp m => Int -> Simulation m (LCFSResource m)
- newLCFSResourceWithMaxCount :: MonadComp m => Int -> Maybe Int -> Simulation m (LCFSResource m)
- newSIROResource :: MonadComp m => Int -> Simulation m (SIROResource m)
- newSIROResourceWithMaxCount :: MonadComp m => Int -> Maybe Int -> Simulation m (SIROResource m)
- newPriorityResource :: MonadComp m => Int -> Simulation m (PriorityResource m)
- newPriorityResourceWithMaxCount :: MonadComp m => Int -> Maybe Int -> Simulation m (PriorityResource m)
- newResource :: (MonadComp m, QueueStrategy m s) => s -> Int -> Simulation m (Resource m s)
- newResourceWithMaxCount :: (MonadComp m, QueueStrategy m s) => s -> Int -> Maybe Int -> Simulation m (Resource m s)
- resourceStrategy :: Resource m s -> s
- resourceMaxCount :: Resource m s -> Maybe Int
- resourceCount :: MonadComp m => Resource m s -> Event m Int
- requestResource :: (MonadComp m, EnqueueStrategy m s) => Resource m s -> Process m ()
- requestResourceWithPriority :: (MonadComp m, PriorityQueueStrategy m s p) => Resource m s -> p -> Process m ()
- tryRequestResourceWithinEvent :: MonadComp m => Resource m s -> Event m Bool
- releaseResource :: (MonadComp m, DequeueStrategy m s) => Resource m s -> Process m ()
- releaseResourceWithinEvent :: (MonadComp m, DequeueStrategy m s) => Resource m s -> Event m ()
- usingResource :: (MonadComp m, EnqueueStrategy m s) => Resource m s -> Process m a -> Process m a
- usingResourceWithPriority :: (MonadComp m, PriorityQueueStrategy m s p) => Resource m s -> p -> Process m a -> Process m a
Resource Types
type FCFSResource m = Resource m FCFS Source
The ordinary FCFS (First Come - First Serviced) resource.
type LCFSResource m = Resource m LCFS Source
The ordinary LCFS (Last Come - First Serviced) resource.
type SIROResource m = Resource m SIRO Source
The SIRO (Serviced in Random Order) resource.
type PriorityResource m = Resource m StaticPriorities Source
The resource with static priorities.
Creating Resource
:: MonadComp m | |
=> Int | the initial count (and maximal count too) of the resource |
-> Simulation m (FCFSResource m) |
Create a new FCFS resource with the specified initial count which value becomes the upper bound as well.
newFCFSResourceWithMaxCount Source
:: MonadComp m | |
=> Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation m (FCFSResource m) |
Create a new FCFS resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: MonadComp m | |
=> Int | the initial count (and maximal count too) of the resource |
-> Simulation m (LCFSResource m) |
Create a new LCFS resource with the specified initial count which value becomes the upper bound as well.
newLCFSResourceWithMaxCount Source
:: MonadComp m | |
=> Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation m (LCFSResource m) |
Create a new LCFS resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: MonadComp m | |
=> Int | the initial count (and maximal count too) of the resource |
-> Simulation m (SIROResource m) |
Create a new SIRO resource with the specified initial count which value becomes the upper bound as well.
newSIROResourceWithMaxCount Source
:: MonadComp m | |
=> Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation m (SIROResource m) |
Create a new SIRO resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: MonadComp m | |
=> Int | the initial count (and maximal count too) of the resource |
-> Simulation m (PriorityResource m) |
Create a new priority resource with the specified initial count which value becomes the upper bound as well.
newPriorityResourceWithMaxCount Source
:: MonadComp m | |
=> Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation m (PriorityResource m) |
Create a new priority resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: (MonadComp m, QueueStrategy m s) | |
=> s | the strategy for managing the queuing requests |
-> Int | the initial count (and maximal count too) of the resource |
-> Simulation m (Resource m s) |
Create a new resource with the specified queue strategy and initial count. The last value becomes the upper bound as well.
newResourceWithMaxCount Source
:: (MonadComp m, QueueStrategy m s) | |
=> s | the strategy for managing the queuing requests |
-> Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation m (Resource m s) |
Create a new resource with the specified queue strategy, initial and maximum counts,
where Nothing
means that the resource has no upper bound.
Resource Properties
resourceStrategy :: Resource m s -> s Source
Return the strategy applied for queuing the requests.
resourceMaxCount :: Resource m s -> Maybe Int Source
Return the maximum count of the resource, where Nothing
means that the resource has no upper bound.
resourceCount :: MonadComp m => Resource m s -> Event m Int Source
Return the current count of the resource.
Requesting for and Releasing Resource
:: (MonadComp m, EnqueueStrategy m s) | |
=> Resource m s | the requested resource |
-> Process m () |
Request for the resource decreasing its count in case of success, otherwise suspending the discontinuous process until some other process releases the resource.
requestResourceWithPriority Source
:: (MonadComp m, PriorityQueueStrategy m s p) | |
=> Resource m s | the requested resource |
-> p | the 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.
:: (MonadComp m, DequeueStrategy m s) | |
=> Resource m s | the resource to release |
-> Process m () |
Release the resource increasing its count and resuming one of the previously suspended processes as possible.
releaseResourceWithinEvent Source
:: (MonadComp m, DequeueStrategy m s) | |
=> Resource m s | the resource to release |
-> Event m () |
Release the resource increasing its count and resuming one of the previously suspended processes as possible.
:: (MonadComp m, EnqueueStrategy m s) | |
=> Resource m s | the resource we are going to request for and then release in the end |
-> Process m a | the action we are going to apply having the resource |
-> Process m a | the result of the action |
Acquire the resource, perform some action and safely release the resource
in the end, even if the IOException
was raised within the action.
usingResourceWithPriority Source
:: (MonadComp m, PriorityQueueStrategy m s p) | |
=> Resource m s | the resource we are going to request for and then release in the end |
-> p | the 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.