Copyright | Copyright (c) 2009-2016, 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 8.0.1
This module defines the preemptible resource.
- data Resource
- newResource :: Int -> Event Resource
- newResourceWithMaxCount :: Int -> Maybe Int -> Event Resource
- resourceMaxCount :: Resource -> Maybe Int
- resourceCount :: Resource -> Event Int
- resourceCountStats :: Resource -> Event (TimingStats Int)
- resourceUtilisationCount :: Resource -> Event Int
- resourceUtilisationCountStats :: Resource -> Event (TimingStats Int)
- resourceQueueCount :: Resource -> Event Int
- resourceQueueCountStats :: Resource -> Event (TimingStats Int)
- resourceTotalWaitTime :: Resource -> Event Double
- resourceWaitTime :: Resource -> Event (SamplingStats Double)
- requestResourceWithPriority :: Resource -> Double -> Process ()
- releaseResource :: Resource -> Process ()
- usingResourceWithPriority :: Resource -> Double -> Process a -> Process a
- incResourceCount :: Resource -> Int -> Event ()
- decResourceCount :: Resource -> Int -> Event ()
- alterResourceCount :: Resource -> Int -> Event ()
- resourceCountChanged :: Resource -> Signal Int
- resourceCountChanged_ :: Resource -> Signal ()
- resourceUtilisationCountChanged :: Resource -> Signal Int
- resourceUtilisationCountChanged_ :: Resource -> Signal ()
- resourceQueueCountChanged :: Resource -> Signal Int
- resourceQueueCountChanged_ :: Resource -> Signal ()
- resourceWaitTimeChanged :: Resource -> Signal (SamplingStats Double)
- resourceWaitTimeChanged_ :: Resource -> Signal ()
- resourceChanged_ :: Resource -> Signal ()
Resource Type
Represents a preemptible resource.
Creating Resource
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 |
-> Event Resource |
Create a new resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
Resource Properties
resourceMaxCount :: Resource -> Maybe Int Source #
Return the maximum count of the resource, where Nothing
means that the resource has no upper bound.
resourceCountStats :: Resource -> Event (TimingStats Int) Source #
Return the statistics for the available count of the resource.
resourceUtilisationCount :: Resource -> Event Int Source #
Return the current utilisation count of the resource.
resourceUtilisationCountStats :: Resource -> Event (TimingStats Int) Source #
Return the statistics for the utilisation count of the resource.
resourceQueueCount :: Resource -> Event Int Source #
Return the current queue length of the resource.
resourceQueueCountStats :: Resource -> Event (TimingStats Int) Source #
Return the statistics for the queue length of the resource.
resourceTotalWaitTime :: Resource -> Event Double Source #
Return the total wait time of the resource.
resourceWaitTime :: Resource -> Event (SamplingStats Double) Source #
Return the statistics for the wait time of the resource.
Requesting for and Releasing Resource
requestResourceWithPriority Source #
:: Resource | the requested resource |
-> Double | the priority (the less value has a higher 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.
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 | 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 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.
Altering Resource
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.
Signals
resourceCountChanged :: Resource -> Signal Int Source #
Signal triggered when the resourceCount
property changes.
resourceCountChanged_ :: Resource -> Signal () Source #
Signal triggered when the resourceCount
property changes.
resourceUtilisationCountChanged :: Resource -> Signal Int Source #
Signal triggered when the resourceUtilisationCount
property changes.
resourceUtilisationCountChanged_ :: Resource -> Signal () Source #
Signal triggered when the resourceUtilisationCount
property changes.
resourceQueueCountChanged :: Resource -> Signal Int Source #
Signal triggered when the resourceQueueCount
property changes.
resourceQueueCountChanged_ :: Resource -> Signal () Source #
Signal triggered when the resourceQueueCount
property changes.
resourceWaitTimeChanged :: Resource -> Signal (SamplingStats Double) Source #
Signal triggered when the resourceTotalWaitTime
and resourceWaitTime
properties change.
resourceWaitTimeChanged_ :: Resource -> Signal () Source #
Signal triggered when the resourceTotalWaitTime
and resourceWaitTime
properties change.
resourceChanged_ :: Resource -> Signal () Source #
Signal triggered when one of the resource counters changes.