Copyright | Copyright (c) 2009-2013, David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
Tested with: GHC 7.6.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 = Resource FCFS DoubleLinkedList
- type LCFSResource = Resource LCFS DoubleLinkedList
- type SIROResource = Resource SIRO Vector
- type PriorityResource = Resource StaticPriorities PriorityQueue
- data Resource s q
- newFCFSResource :: Int -> Simulation FCFSResource
- newFCFSResourceWithMaxCount :: Int -> Maybe Int -> Simulation FCFSResource
- newLCFSResource :: Int -> Simulation LCFSResource
- newLCFSResourceWithMaxCount :: Int -> Maybe Int -> Simulation LCFSResource
- newSIROResource :: Int -> Simulation SIROResource
- newSIROResourceWithMaxCount :: Int -> Maybe Int -> Simulation SIROResource
- newPriorityResource :: Int -> Simulation PriorityResource
- newPriorityResourceWithMaxCount :: Int -> Maybe Int -> Simulation PriorityResource
- newResource :: QueueStrategy s q => s -> Int -> Simulation (Resource s q)
- newResourceWithMaxCount :: QueueStrategy s q => s -> Int -> Maybe Int -> Simulation (Resource s q)
- resourceStrategy :: Resource s q -> s
- resourceMaxCount :: Resource s q -> Maybe Int
- resourceCount :: Resource s q -> Event Int
- requestResource :: EnqueueStrategy s q => Resource s q -> Process ()
- requestResourceWithPriority :: PriorityQueueStrategy s q p => Resource s q -> p -> Process ()
- tryRequestResourceWithinEvent :: Resource s q -> Event Bool
- releaseResource :: DequeueStrategy s q => Resource s q -> Process ()
- releaseResourceWithinEvent :: DequeueStrategy s q => Resource s q -> Event ()
- usingResource :: EnqueueStrategy s q => Resource s q -> Process a -> Process a
- usingResourceWithPriority :: PriorityQueueStrategy s q p => Resource s q -> p -> Process a -> Process a
Resource Types
type FCFSResource = Resource FCFS DoubleLinkedList Source
The ordinary FCFS (First Come - First Serviced) resource.
type LCFSResource = Resource LCFS DoubleLinkedList Source
The ordinary LCFS (Last Come - First Serviced) resource.
type SIROResource = Resource SIRO Vector Source
The SIRO (Serviced in Random Order) resource.
type PriorityResource = Resource StaticPriorities PriorityQueue Source
The resource with static priorities.
Represents the resource with strategy s
applied for queuing the requests.
The q
type is dependent and it is usually derived automatically.
Creating Resource
:: Int | the initial count (and maximal count too) of the resource |
-> Simulation FCFSResource |
Create a new FCFS resource with the specified initial count which value becomes the upper bound as well.
newFCFSResourceWithMaxCount Source
:: Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation FCFSResource |
Create a new FCFS resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: Int | the initial count (and maximal count too) of the resource |
-> Simulation LCFSResource |
Create a new LCFS resource with the specified initial count which value becomes the upper bound as well.
newLCFSResourceWithMaxCount Source
:: Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation LCFSResource |
Create a new LCFS resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: Int | the initial count (and maximal count too) of the resource |
-> Simulation SIROResource |
Create a new SIRO resource with the specified initial count which value becomes the upper bound as well.
newSIROResourceWithMaxCount Source
:: Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation SIROResource |
Create a new SIRO resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: Int | the initial count (and maximal count too) of the resource |
-> Simulation PriorityResource |
Create a new priority resource with the specified initial count which value becomes the upper bound as well.
newPriorityResourceWithMaxCount Source
:: Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Simulation PriorityResource |
Create a new priority resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: QueueStrategy s q | |
=> s | the strategy for managing the queuing requests |
-> Int | the initial count (and maximal count too) of the resource |
-> Simulation (Resource s q) |
Create a new resource with the specified queue strategy and initial count. The last value becomes the upper bound as well.
newResourceWithMaxCount Source
:: QueueStrategy s q | |
=> 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 (Resource s q) |
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 s q -> s Source
Return the strategy applied for queuing the requests.
resourceMaxCount :: Resource s q -> Maybe Int Source
Return the maximum count of the resource, where Nothing
means that the resource has no upper bound.
resourceCount :: Resource s q -> Event Int Source
Return the current count of the resource.
Requesting for and Releasing Resource
:: EnqueueStrategy s q | |
=> Resource s q | the requested resource |
-> Process () |
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
:: PriorityQueueStrategy s q p | |
=> Resource s q | the requested resource |
-> p | the priority |
-> Process () |
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.
:: DequeueStrategy s q | |
=> Resource s q | the resource to release |
-> Process () |
Release the resource increasing its count and resuming one of the previously suspended processes as possible.
releaseResourceWithinEvent Source
:: DequeueStrategy s q | |
=> Resource s q | the resource to release |
-> Event () |
Release the resource increasing its count and resuming one of the previously suspended processes as possible.
:: EnqueueStrategy s q | |
=> Resource s q | the resource we are going to request for and then release in the end |
-> Process a | the action we are going to apply having the resource |
-> Process 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
:: PriorityQueueStrategy s q p | |
=> Resource s q | the resource we are going to request for and then release in the end |
-> p | the priority |
-> Process a | the action we are going to apply having the resource |
-> Process 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.