{-# LANGUAGE FlexibleContexts #-}

-- |
-- Module     : Simulation.Aivika.Trans.Queue
-- Copyright  : Copyright (c) 2009-2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.1
--
-- This module defines a queue that can use the specified strategies. So, having only
-- the 'FCFS', 'LCFS', 'SIRO' and 'StaticPriorities' strategies, you can build
-- 4 x 4 x 4 = 64 different types of the queue, each of them will have its own
-- behaviour.
--
module Simulation.Aivika.Trans.Queue
       (-- * Queue Types
        FCFSQueue,
        LCFSQueue,
        SIROQueue,
        PriorityQueue,
        Queue,
        -- * Creating Queue
        newFCFSQueue,
        newLCFSQueue,
        newSIROQueue,
        newPriorityQueue,
        newQueue,
        -- * Queue Properties and Activities
        enqueueStrategy,
        enqueueStoringStrategy,
        dequeueStrategy,
        queueNull,
        queueFull,
        queueMaxCount,
        queueCount,
        queueCountStats,
        enqueueCount,
        enqueueLostCount,
        enqueueStoreCount,
        dequeueCount,
        dequeueExtractCount,
        queueLoadFactor,
        enqueueRate,
        enqueueStoreRate,
        dequeueRate,
        dequeueExtractRate,
        queueWaitTime,
        queueTotalWaitTime,
        enqueueWaitTime,
        dequeueWaitTime,
        queueRate,
        -- * Dequeuing and Enqueuing
        dequeue,
        dequeueWithOutputPriority,
        tryDequeue,
        enqueue,
        enqueueWithInputPriority,
        enqueueWithStoringPriority,
        enqueueWithInputStoringPriorities,
        tryEnqueue,
        tryEnqueueWithStoringPriority,
        enqueueOrLost,
        enqueueOrLost_,
        enqueueWithStoringPriorityOrLost,
        enqueueWithStoringPriorityOrLost_,
        queueDelete,
        queueDelete_,
        queueDeleteBy,
        queueDeleteBy_,
        queueContains,
        queueContainsBy,
        clearQueue,
        -- * Statistics Reset
        resetQueue,
        -- * Awaiting
        waitWhileFullQueue,
        -- * Summary
        queueSummary,
        -- * Derived Signals for Properties
        queueNullChanged,
        queueNullChanged_,
        queueFullChanged,
        queueFullChanged_,
        queueCountChanged,
        queueCountChanged_,
        enqueueCountChanged,
        enqueueCountChanged_,
        enqueueLostCountChanged,
        enqueueLostCountChanged_,
        enqueueStoreCountChanged,
        enqueueStoreCountChanged_,
        dequeueCountChanged,
        dequeueCountChanged_,
        dequeueExtractCountChanged,
        dequeueExtractCountChanged_,
        queueLoadFactorChanged,
        queueLoadFactorChanged_,
        queueWaitTimeChanged,
        queueWaitTimeChanged_,
        queueTotalWaitTimeChanged,
        queueTotalWaitTimeChanged_,
        enqueueWaitTimeChanged,
        enqueueWaitTimeChanged_,
        dequeueWaitTimeChanged,
        dequeueWaitTimeChanged_,
        queueRateChanged,
        queueRateChanged_,
        -- * Basic Signals
        enqueueInitiated,
        enqueueStored,
        enqueueLost,
        dequeueRequested,
        dequeueExtracted,
        -- * Overall Signal
        queueChanged_) where

import Data.Monoid
import Data.Maybe

import Control.Monad
import Control.Monad.Trans

import Simulation.Aivika.Trans.Ref.Base
import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Internal.Specs
import Simulation.Aivika.Trans.Internal.Parameter
import Simulation.Aivika.Trans.Internal.Simulation
import Simulation.Aivika.Trans.Internal.Dynamics
import Simulation.Aivika.Trans.Internal.Event
import Simulation.Aivika.Trans.Internal.Process
import Simulation.Aivika.Trans.Signal
import Simulation.Aivika.Trans.Resource.Base
import Simulation.Aivika.Trans.QueueStrategy
import Simulation.Aivika.Trans.Statistics

-- | A type synonym for the ordinary FIFO queue also known as the FCFS
-- (First Come - First Serviced) queue.
type FCFSQueue m a = Queue m FCFS FCFS FCFS a

-- | A type synonym for the ordinary LIFO queue also known as the LCFS
-- (Last Come - First Serviced) queue.
type LCFSQueue m a = Queue m FCFS LCFS FCFS a

-- | A type synonym for the SIRO (Serviced in Random Order) queue.
type SIROQueue m a = Queue m FCFS SIRO FCFS a

-- | A type synonym for the queue with static priorities applied when
-- storing the elements in the queue.
type PriorityQueue m a = Queue m FCFS StaticPriorities FCFS a

-- | Represents a queue using the specified strategies for enqueueing (input), @si@,
-- internal storing (in memory), @sm@, and dequeueing (output), @so@, where @a@ denotes
-- the type of items stored in the queue. Type @m@ denotes the underlying monad within
-- which the simulation executes.
data Queue m si sm so a =
  Queue { Queue m si sm so a -> Int
queueMaxCount :: Int,
          -- ^ The queue capacity.
          Queue m si sm so a -> si
enqueueStrategy :: si,
          -- ^ The strategy applied to the enqueueing (input) processes when the queue is full.
          Queue m si sm so a -> sm
enqueueStoringStrategy :: sm,
          -- ^ The strategy applied when storing (in memory) items in the queue.
          Queue m si sm so a -> so
dequeueStrategy :: so,
          -- ^ The strategy applied to the dequeueing (output) processes when the queue is empty.
          Queue m si sm so a -> Resource m si
enqueueRes :: Resource m si,
          Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
queueStore :: StrategyQueue m sm (QueueItem a),
          Queue m si sm so a -> Resource m so
dequeueRes :: Resource m so,
          Queue m si sm so a -> Ref m Int
queueCountRef :: Ref m Int,
          Queue m si sm so a -> Ref m (TimingStats Int)
queueCountStatsRef :: Ref m (TimingStats Int),
          Queue m si sm so a -> Ref m Int
enqueueCountRef :: Ref m Int,
          Queue m si sm so a -> Ref m Int
enqueueLostCountRef :: Ref m Int,
          Queue m si sm so a -> Ref m Int
enqueueStoreCountRef :: Ref m Int,
          Queue m si sm so a -> Ref m Int
dequeueCountRef :: Ref m Int,
          Queue m si sm so a -> Ref m Int
dequeueExtractCountRef :: Ref m Int,
          Queue m si sm so a -> Ref m (SamplingStats Double)
queueWaitTimeRef :: Ref m (SamplingStats Double),
          Queue m si sm so a -> Ref m (SamplingStats Double)
queueTotalWaitTimeRef :: Ref m (SamplingStats Double),
          Queue m si sm so a -> Ref m (SamplingStats Double)
enqueueWaitTimeRef :: Ref m (SamplingStats Double),
          Queue m si sm so a -> Ref m (SamplingStats Double)
dequeueWaitTimeRef :: Ref m (SamplingStats Double),
          Queue m si sm so a -> SignalSource m a
enqueueInitiatedSource :: SignalSource m a,
          Queue m si sm so a -> SignalSource m a
enqueueLostSource :: SignalSource m a,
          Queue m si sm so a -> SignalSource m a
enqueueStoredSource :: SignalSource m a,
          Queue m si sm so a -> SignalSource m ()
dequeueRequestedSource :: SignalSource m (),
          Queue m si sm so a -> SignalSource m a
dequeueExtractedSource :: SignalSource m a }

-- | Stores the item and a time of its enqueuing. 
data QueueItem a =
  QueueItem { QueueItem a -> a
itemValue :: a,
              -- ^ Return the item value.
              QueueItem a -> Double
itemInputTime :: Double,
              -- ^ Return the time of enqueuing the item.
              QueueItem a -> Double
itemStoringTime :: Double
              -- ^ Return the time of storing in the queue, or
              -- @itemInputTime@ before the actual storing when
              -- the item was just enqueued.
            }
  
-- | Create a new FCFS queue with the specified capacity.  
newFCFSQueue :: MonadDES m => Int -> Event m (FCFSQueue m a)
{-# INLINABLE newFCFSQueue #-}
newFCFSQueue :: Int -> Event m (FCFSQueue m a)
newFCFSQueue = FCFS -> FCFS -> FCFS -> Int -> Event m (FCFSQueue m a)
forall (m :: * -> *) si sm so a.
(MonadDES m, QueueStrategy m si, QueueStrategy m sm,
 QueueStrategy m so) =>
si -> sm -> so -> Int -> Event m (Queue m si sm so a)
newQueue FCFS
FCFS FCFS
FCFS FCFS
FCFS
  
-- | Create a new LCFS queue with the specified capacity.  
newLCFSQueue :: MonadDES m => Int -> Event m (LCFSQueue m a)  
{-# INLINABLE newLCFSQueue #-}
newLCFSQueue :: Int -> Event m (LCFSQueue m a)
newLCFSQueue = FCFS -> LCFS -> FCFS -> Int -> Event m (LCFSQueue m a)
forall (m :: * -> *) si sm so a.
(MonadDES m, QueueStrategy m si, QueueStrategy m sm,
 QueueStrategy m so) =>
si -> sm -> so -> Int -> Event m (Queue m si sm so a)
newQueue FCFS
FCFS LCFS
LCFS FCFS
FCFS
  
-- | Create a new SIRO queue with the specified capacity.  
newSIROQueue :: (MonadDES m, QueueStrategy m SIRO) => Int -> Event m (SIROQueue m a)  
{-# INLINABLE newSIROQueue #-}
newSIROQueue :: Int -> Event m (SIROQueue m a)
newSIROQueue = FCFS -> SIRO -> FCFS -> Int -> Event m (SIROQueue m a)
forall (m :: * -> *) si sm so a.
(MonadDES m, QueueStrategy m si, QueueStrategy m sm,
 QueueStrategy m so) =>
si -> sm -> so -> Int -> Event m (Queue m si sm so a)
newQueue FCFS
FCFS SIRO
SIRO FCFS
FCFS
  
-- | Create a new priority queue with the specified capacity.  
newPriorityQueue :: (MonadDES m, QueueStrategy m StaticPriorities) => Int -> Event m (PriorityQueue m a)  
{-# INLINABLE newPriorityQueue #-}
newPriorityQueue :: Int -> Event m (PriorityQueue m a)
newPriorityQueue = FCFS
-> StaticPriorities -> FCFS -> Int -> Event m (PriorityQueue m a)
forall (m :: * -> *) si sm so a.
(MonadDES m, QueueStrategy m si, QueueStrategy m sm,
 QueueStrategy m so) =>
si -> sm -> so -> Int -> Event m (Queue m si sm so a)
newQueue FCFS
FCFS StaticPriorities
StaticPriorities FCFS
FCFS
  
-- | Create a new queue with the specified strategies and capacity.  
newQueue :: (MonadDES m,
             QueueStrategy m si,
             QueueStrategy m sm,
             QueueStrategy m so) =>
            si
            -- ^ the strategy applied to the enqueueing (input) processes when the queue is full
            -> sm
            -- ^ the strategy applied when storing items in the queue
            -> so
            -- ^ the strategy applied to the dequeueing (output) processes when the queue is empty
            -> Int
            -- ^ the queue capacity
            -> Event m (Queue m si sm so a)  
{-# INLINABLE newQueue #-}
newQueue :: si -> sm -> so -> Int -> Event m (Queue m si sm so a)
newQueue si
si sm
sm so
so Int
count =
  do Double
t  <- Dynamics m Double -> Event m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
     Ref m Int
i  <- Simulation m (Ref m Int) -> Event m (Ref m Int)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Int) -> Event m (Ref m Int))
-> Simulation m (Ref m Int) -> Event m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Int
0
     Ref m (TimingStats Int)
is <- Simulation m (Ref m (TimingStats Int))
-> Event m (Ref m (TimingStats Int))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m (TimingStats Int))
 -> Event m (Ref m (TimingStats Int)))
-> Simulation m (Ref m (TimingStats Int))
-> Event m (Ref m (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ TimingStats Int -> Simulation m (Ref m (TimingStats Int))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef (TimingStats Int -> Simulation m (Ref m (TimingStats Int)))
-> TimingStats Int -> Simulation m (Ref m (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
0
     Ref m Int
ci <- Simulation m (Ref m Int) -> Event m (Ref m Int)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Int) -> Event m (Ref m Int))
-> Simulation m (Ref m Int) -> Event m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Int
0
     Ref m Int
cl <- Simulation m (Ref m Int) -> Event m (Ref m Int)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Int) -> Event m (Ref m Int))
-> Simulation m (Ref m Int) -> Event m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Int
0
     Ref m Int
cm <- Simulation m (Ref m Int) -> Event m (Ref m Int)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Int) -> Event m (Ref m Int))
-> Simulation m (Ref m Int) -> Event m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Int
0
     Ref m Int
cr <- Simulation m (Ref m Int) -> Event m (Ref m Int)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Int) -> Event m (Ref m Int))
-> Simulation m (Ref m Int) -> Event m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Int
0
     Ref m Int
co <- Simulation m (Ref m Int) -> Event m (Ref m Int)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Int) -> Event m (Ref m Int))
-> Simulation m (Ref m Int) -> Event m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Int
0
     Resource m si
ri <- Simulation m (Resource m si) -> Event m (Resource m si)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Resource m si) -> Event m (Resource m si))
-> Simulation m (Resource m si) -> Event m (Resource m si)
forall a b. (a -> b) -> a -> b
$ si -> Int -> Maybe Int -> Simulation m (Resource m si)
forall (m :: * -> *) s.
(MonadDES m, QueueStrategy m s) =>
s -> Int -> Maybe Int -> Simulation m (Resource m s)
newResourceWithMaxCount si
si Int
count (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
count)
     StrategyQueue m sm (QueueItem a)
qm <- Simulation m (StrategyQueue m sm (QueueItem a))
-> Event m (StrategyQueue m sm (QueueItem a))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (StrategyQueue m sm (QueueItem a))
 -> Event m (StrategyQueue m sm (QueueItem a)))
-> Simulation m (StrategyQueue m sm (QueueItem a))
-> Event m (StrategyQueue m sm (QueueItem a))
forall a b. (a -> b) -> a -> b
$ sm -> Simulation m (StrategyQueue m sm (QueueItem a))
forall (m :: * -> *) s a.
QueueStrategy m s =>
s -> Simulation m (StrategyQueue m s a)
newStrategyQueue sm
sm
     Resource m so
ro <- Simulation m (Resource m so) -> Event m (Resource m so)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Resource m so) -> Event m (Resource m so))
-> Simulation m (Resource m so) -> Event m (Resource m so)
forall a b. (a -> b) -> a -> b
$ so -> Int -> Maybe Int -> Simulation m (Resource m so)
forall (m :: * -> *) s.
(MonadDES m, QueueStrategy m s) =>
s -> Int -> Maybe Int -> Simulation m (Resource m s)
newResourceWithMaxCount so
so Int
0 (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
count)
     Ref m (SamplingStats Double)
w  <- Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m (SamplingStats Double))
 -> Event m (Ref m (SamplingStats Double)))
-> Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. Monoid a => a
mempty
     Ref m (SamplingStats Double)
wt <- Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m (SamplingStats Double))
 -> Event m (Ref m (SamplingStats Double)))
-> Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. Monoid a => a
mempty
     Ref m (SamplingStats Double)
wi <- Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m (SamplingStats Double))
 -> Event m (Ref m (SamplingStats Double)))
-> Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. Monoid a => a
mempty
     Ref m (SamplingStats Double)
wo <- Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m (SamplingStats Double))
 -> Event m (Ref m (SamplingStats Double)))
-> Simulation m (Ref m (SamplingStats Double))
-> Event m (Ref m (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. Monoid a => a
mempty 
     SignalSource m a
s1 <- Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (SignalSource m a) -> Event m (SignalSource m a))
-> Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall a b. (a -> b) -> a -> b
$ Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m a
s2 <- Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (SignalSource m a) -> Event m (SignalSource m a))
-> Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall a b. (a -> b) -> a -> b
$ Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m a
s3 <- Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (SignalSource m a) -> Event m (SignalSource m a))
-> Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall a b. (a -> b) -> a -> b
$ Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m ()
s4 <- Simulation m (SignalSource m ()) -> Event m (SignalSource m ())
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (SignalSource m ()) -> Event m (SignalSource m ()))
-> Simulation m (SignalSource m ()) -> Event m (SignalSource m ())
forall a b. (a -> b) -> a -> b
$ Simulation m (SignalSource m ())
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m a
s5 <- Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (SignalSource m a) -> Event m (SignalSource m a))
-> Simulation m (SignalSource m a) -> Event m (SignalSource m a)
forall a b. (a -> b) -> a -> b
$ Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     Queue m si sm so a -> Event m (Queue m si sm so a)
forall (m :: * -> *) a. Monad m => a -> m a
return Queue :: forall (m :: * -> *) si sm so a.
Int
-> si
-> sm
-> so
-> Resource m si
-> StrategyQueue m sm (QueueItem a)
-> Resource m so
-> Ref m Int
-> Ref m (TimingStats Int)
-> Ref m Int
-> Ref m Int
-> Ref m Int
-> Ref m Int
-> Ref m Int
-> Ref m (SamplingStats Double)
-> Ref m (SamplingStats Double)
-> Ref m (SamplingStats Double)
-> Ref m (SamplingStats Double)
-> SignalSource m a
-> SignalSource m a
-> SignalSource m a
-> SignalSource m ()
-> SignalSource m a
-> Queue m si sm so a
Queue { queueMaxCount :: Int
queueMaxCount = Int
count,
                    enqueueStrategy :: si
enqueueStrategy = si
si,
                    enqueueStoringStrategy :: sm
enqueueStoringStrategy = sm
sm,
                    dequeueStrategy :: so
dequeueStrategy = so
so,
                    enqueueRes :: Resource m si
enqueueRes = Resource m si
ri,
                    queueStore :: StrategyQueue m sm (QueueItem a)
queueStore = StrategyQueue m sm (QueueItem a)
qm,
                    dequeueRes :: Resource m so
dequeueRes = Resource m so
ro,
                    queueCountRef :: Ref m Int
queueCountRef = Ref m Int
i,
                    queueCountStatsRef :: Ref m (TimingStats Int)
queueCountStatsRef = Ref m (TimingStats Int)
is,
                    enqueueCountRef :: Ref m Int
enqueueCountRef = Ref m Int
ci,
                    enqueueLostCountRef :: Ref m Int
enqueueLostCountRef = Ref m Int
cl,
                    enqueueStoreCountRef :: Ref m Int
enqueueStoreCountRef = Ref m Int
cm,
                    dequeueCountRef :: Ref m Int
dequeueCountRef = Ref m Int
cr,
                    dequeueExtractCountRef :: Ref m Int
dequeueExtractCountRef = Ref m Int
co,
                    queueWaitTimeRef :: Ref m (SamplingStats Double)
queueWaitTimeRef = Ref m (SamplingStats Double)
w,
                    queueTotalWaitTimeRef :: Ref m (SamplingStats Double)
queueTotalWaitTimeRef = Ref m (SamplingStats Double)
wt,
                    enqueueWaitTimeRef :: Ref m (SamplingStats Double)
enqueueWaitTimeRef = Ref m (SamplingStats Double)
wi,
                    dequeueWaitTimeRef :: Ref m (SamplingStats Double)
dequeueWaitTimeRef = Ref m (SamplingStats Double)
wo,
                    enqueueInitiatedSource :: SignalSource m a
enqueueInitiatedSource = SignalSource m a
s1,
                    enqueueLostSource :: SignalSource m a
enqueueLostSource = SignalSource m a
s2,
                    enqueueStoredSource :: SignalSource m a
enqueueStoredSource = SignalSource m a
s3,
                    dequeueRequestedSource :: SignalSource m ()
dequeueRequestedSource = SignalSource m ()
s4,
                    dequeueExtractedSource :: SignalSource m a
dequeueExtractedSource = SignalSource m a
s5 }
  
-- | Test whether the queue is empty.
--
-- See also 'queueNullChanged' and 'queueNullChanged_'.
queueNull :: MonadDES m => Queue m si sm so a -> Event m Bool
{-# INLINABLE queueNull #-}
queueNull :: Queue m si sm so a -> Event m Bool
queueNull Queue m si sm so a
q =
  (Point m -> m Bool) -> Event m Bool
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Bool) -> Event m Bool)
-> (Point m -> m Bool) -> Event m Bool
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
n <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q)
     Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0)
  
-- | Signal when the 'queueNull' property value has changed.
queueNullChanged :: MonadDES m => Queue m si sm so a -> Signal m Bool
{-# INLINABLE queueNullChanged #-}
queueNullChanged :: Queue m si sm so a -> Signal m Bool
queueNullChanged Queue m si sm so a
q =
  (() -> Event m Bool) -> Signal m () -> Signal m Bool
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Bool -> () -> Event m Bool
forall a b. a -> b -> a
const (Event m Bool -> () -> Event m Bool)
-> Event m Bool -> () -> Event m Bool
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Bool
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Bool
queueNull Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
queueNullChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'queueNull' property value has changed.
queueNullChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE queueNullChanged_ #-}
queueNullChanged_ :: Queue m si sm so a -> Signal m ()
queueNullChanged_ = Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
queueCountChanged_

-- | Test whether the queue is full.
--
-- See also 'queueFullChanged' and 'queueFullChanged_'.
queueFull :: MonadDES m => Queue m si sm so a -> Event m Bool
{-# INLINABLE queueFull #-}
queueFull :: Queue m si sm so a -> Event m Bool
queueFull Queue m si sm so a
q =
  (Point m -> m Bool) -> Event m Bool
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Bool) -> Event m Bool)
-> (Point m -> m Bool) -> Event m Bool
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
n <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q)
     Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Queue m si sm so a -> Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Int
queueMaxCount Queue m si sm so a
q)
  
-- | Signal when the 'queueFull' property value has changed.
queueFullChanged :: MonadDES m => Queue m si sm so a -> Signal m Bool
{-# INLINABLE queueFullChanged #-}
queueFullChanged :: Queue m si sm so a -> Signal m Bool
queueFullChanged Queue m si sm so a
q =
  (() -> Event m Bool) -> Signal m () -> Signal m Bool
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Bool -> () -> Event m Bool
forall a b. a -> b -> a
const (Event m Bool -> () -> Event m Bool)
-> Event m Bool -> () -> Event m Bool
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Bool
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Bool
queueFull Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
queueFullChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'queueFull' property value has changed.
queueFullChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE queueFullChanged_ #-}
queueFullChanged_ :: Queue m si sm so a -> Signal m ()
queueFullChanged_ = Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
queueCountChanged_

-- | Return the current queue size.
--
-- See also 'queueCountStats', 'queueCountChanged' and 'queueCountChanged_'.
queueCount :: MonadDES m => Queue m si sm so a -> Event m Int
{-# INLINABLE queueCount #-}
queueCount :: Queue m si sm so a -> Event m Int
queueCount Queue m si sm so a
q =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q)

-- | Return the queue size statistics.
queueCountStats :: MonadDES m => Queue m si sm so a -> Event m (TimingStats Int)
{-# INLINABLE queueCountStats #-}
queueCountStats :: Queue m si sm so a -> Event m (TimingStats Int)
queueCountStats Queue m si sm so a
q =
  (Point m -> m (TimingStats Int)) -> Event m (TimingStats Int)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (TimingStats Int)) -> Event m (TimingStats Int))
-> (Point m -> m (TimingStats Int)) -> Event m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m (TimingStats Int) -> m (TimingStats Int)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (TimingStats Int) -> m (TimingStats Int))
-> Event m (TimingStats Int) -> m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> Event m (TimingStats Int)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m (TimingStats Int)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (TimingStats Int)
queueCountStatsRef Queue m si sm so a
q)
  
-- | Signal when the 'queueCount' property value has changed.
queueCountChanged :: MonadDES m => Queue m si sm so a -> Signal m Int
{-# INLINABLE queueCountChanged #-}
queueCountChanged :: Queue m si sm so a -> Signal m Int
queueCountChanged Queue m si sm so a
q =
  (() -> Event m Int) -> Signal m () -> Signal m Int
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Int -> () -> Event m Int
forall a b. a -> b -> a
const (Event m Int -> () -> Event m Int)
-> Event m Int -> () -> Event m Int
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
queueCount Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
queueCountChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'queueCount' property value has changed.
queueCountChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE queueCountChanged_ #-}
queueCountChanged_ :: Queue m si sm so a -> Signal m ()
queueCountChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueStored Queue m si sm so a
q) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q)

-- | Return the total number of input items that were enqueued.
--
-- See also 'enqueueCountChanged' and 'enqueueCountChanged_'.
enqueueCount :: MonadDES m => Queue m si sm so a -> Event m Int
{-# INLINABLE enqueueCount #-}
enqueueCount :: Queue m si sm so a -> Event m Int
enqueueCount Queue m si sm so a
q =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueCountRef Queue m si sm so a
q)
  
-- | Signal when the 'enqueueCount' property value has changed.
enqueueCountChanged :: MonadDES m => Queue m si sm so a -> Signal m Int
{-# INLINABLE enqueueCountChanged #-}
enqueueCountChanged :: Queue m si sm so a -> Signal m Int
enqueueCountChanged Queue m si sm so a
q =
  (() -> Event m Int) -> Signal m () -> Signal m Int
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Int -> () -> Event m Int
forall a b. a -> b -> a
const (Event m Int -> () -> Event m Int)
-> Event m Int -> () -> Event m Int
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
enqueueCount Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
enqueueCountChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'enqueueCount' property value has changed.
enqueueCountChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE enqueueCountChanged_ #-}
enqueueCountChanged_ :: Queue m si sm so a -> Signal m ()
enqueueCountChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueInitiated Queue m si sm so a
q)
  
-- | Return the number of lost items.
--
-- See also 'enqueueLostCountChanged' and 'enqueueLostCountChanged_'.
enqueueLostCount :: MonadDES m => Queue m si sm so a -> Event m Int
{-# INLINABLE enqueueLostCount #-}
enqueueLostCount :: Queue m si sm so a -> Event m Int
enqueueLostCount Queue m si sm so a
q =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueLostCountRef Queue m si sm so a
q)
  
-- | Signal when the 'enqueueLostCount' property value has changed.
enqueueLostCountChanged :: MonadDES m => Queue m si sm so a -> Signal m Int
{-# INLINABLE enqueueLostCountChanged #-}
enqueueLostCountChanged :: Queue m si sm so a -> Signal m Int
enqueueLostCountChanged Queue m si sm so a
q =
  (() -> Event m Int) -> Signal m () -> Signal m Int
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Int -> () -> Event m Int
forall a b. a -> b -> a
const (Event m Int -> () -> Event m Int)
-> Event m Int -> () -> Event m Int
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
enqueueLostCount Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
enqueueLostCountChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'enqueueLostCount' property value has changed.
enqueueLostCountChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE enqueueLostCountChanged_ #-}
enqueueLostCountChanged_ :: Queue m si sm so a -> Signal m ()
enqueueLostCountChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueLost Queue m si sm so a
q)
      
-- | Return the total number of input items that were stored.
--
-- See also 'enqueueStoreCountChanged' and 'enqueueStoreCountChanged_'.
enqueueStoreCount :: MonadDES m => Queue m si sm so a -> Event m Int
{-# INLINABLE enqueueStoreCount #-}
enqueueStoreCount :: Queue m si sm so a -> Event m Int
enqueueStoreCount Queue m si sm so a
q =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueStoreCountRef Queue m si sm so a
q)
  
-- | Signal when the 'enqueueStoreCount' property value has changed.
enqueueStoreCountChanged :: MonadDES m => Queue m si sm so a -> Signal m Int
{-# INLINABLE enqueueStoreCountChanged #-}
enqueueStoreCountChanged :: Queue m si sm so a -> Signal m Int
enqueueStoreCountChanged Queue m si sm so a
q =
  (() -> Event m Int) -> Signal m () -> Signal m Int
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Int -> () -> Event m Int
forall a b. a -> b -> a
const (Event m Int -> () -> Event m Int)
-> Event m Int -> () -> Event m Int
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
enqueueStoreCount Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
enqueueStoreCountChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'enqueueStoreCount' property value has changed.
enqueueStoreCountChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE enqueueStoreCountChanged_ #-}
enqueueStoreCountChanged_ :: Queue m si sm so a -> Signal m ()
enqueueStoreCountChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueStored Queue m si sm so a
q)
      
-- | Return the total number of requests for dequeueing the items,
-- not taking into account the failed attempts to dequeue immediately
-- without suspension.
--
-- See also 'dequeueCountChanged' and 'dequeueCountChanged_'.
dequeueCount :: MonadDES m => Queue m si sm so a -> Event m Int
{-# INLINABLE dequeueCount #-}
dequeueCount :: Queue m si sm so a -> Event m Int
dequeueCount Queue m si sm so a
q =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
dequeueCountRef Queue m si sm so a
q)
      
-- | Signal when the 'dequeueCount' property value has changed.
dequeueCountChanged :: MonadDES m => Queue m si sm so a -> Signal m Int
{-# INLINABLE dequeueCountChanged #-}
dequeueCountChanged :: Queue m si sm so a -> Signal m Int
dequeueCountChanged Queue m si sm so a
q =
  (() -> Event m Int) -> Signal m () -> Signal m Int
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Int -> () -> Event m Int
forall a b. a -> b -> a
const (Event m Int -> () -> Event m Int)
-> Event m Int -> () -> Event m Int
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
dequeueCount Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
dequeueCountChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'dequeueCount' property value has changed.
dequeueCountChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE dequeueCountChanged_ #-}
dequeueCountChanged_ :: Queue m si sm so a -> Signal m ()
dequeueCountChanged_ Queue m si sm so a
q =
  (() -> ()) -> Signal m () -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> () -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
dequeueRequested Queue m si sm so a
q)
      
-- | Return the total number of output items that were actually dequeued.
--
-- See also 'dequeueExtractCountChanged' and 'dequeueExtractCountChanged_'.
dequeueExtractCount :: MonadDES m => Queue m si sm so a -> Event m Int
{-# INLINABLE dequeueExtractCount #-}
dequeueExtractCount :: Queue m si sm so a -> Event m Int
dequeueExtractCount Queue m si sm so a
q =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
dequeueExtractCountRef Queue m si sm so a
q)
      
-- | Signal when the 'dequeueExtractCount' property value has changed.
dequeueExtractCountChanged :: MonadDES m => Queue m si sm so a -> Signal m Int
{-# INLINABLE dequeueExtractCountChanged #-}
dequeueExtractCountChanged :: Queue m si sm so a -> Signal m Int
dequeueExtractCountChanged Queue m si sm so a
q =
  (() -> Event m Int) -> Signal m () -> Signal m Int
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Int -> () -> Event m Int
forall a b. a -> b -> a
const (Event m Int -> () -> Event m Int)
-> Event m Int -> () -> Event m Int
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
dequeueExtractCount Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
dequeueExtractCountChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'dequeueExtractCount' property value has changed.
dequeueExtractCountChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE dequeueExtractCountChanged_ #-}
dequeueExtractCountChanged_ :: Queue m si sm so a -> Signal m ()
dequeueExtractCountChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q)

-- | Return the load factor: the queue size divided by its maximum size.
--
-- See also 'queueLoadFactorChanged' and 'queueLoadFactorChanged_'.
queueLoadFactor :: MonadDES m => Queue m si sm so a -> Event m Double
{-# INLINABLE queueLoadFactor #-}
queueLoadFactor :: Queue m si sm so a -> Event m Double
queueLoadFactor Queue m si sm so a
q =
  (Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
x <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q)
     let y :: Int
y = Queue m si sm so a -> Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Int
queueMaxCount Queue m si sm so a
q
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
y)
      
-- | Signal when the 'queueLoadFactor' property value has changed.
queueLoadFactorChanged :: MonadDES m => Queue m si sm so a -> Signal m Double
{-# INLINABLE queueLoadFactorChanged #-}
queueLoadFactorChanged :: Queue m si sm so a -> Signal m Double
queueLoadFactorChanged Queue m si sm so a
q =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
queueLoadFactor Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
queueLoadFactorChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'queueLoadFactor' property value has changed.
queueLoadFactorChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE queueLoadFactorChanged_ #-}
queueLoadFactorChanged_ :: Queue m si sm so a -> Signal m ()
queueLoadFactorChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueStored Queue m si sm so a
q) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q)
      
-- | Return the rate of the input items that were enqueued: how many items
-- per time.
enqueueRate :: MonadDES m => Queue m si sm so a -> Event m Double
{-# INLINABLE enqueueRate #-}
enqueueRate :: Queue m si sm so a -> Event m Double
enqueueRate Queue m si sm so a
q =
  (Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
x <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueCountRef Queue m si sm so a
q)
     let t0 :: Double
t0 = Specs m -> Double
forall (m :: * -> *). Specs m -> Double
spcStartTime (Specs m -> Double) -> Specs m -> Double
forall a b. (a -> b) -> a -> b
$ Point m -> Specs m
forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
         t :: Double
t  = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0))
      
-- | Return the rate of the items that were stored: how many items
-- per time.
enqueueStoreRate :: MonadDES m => Queue m si sm so a -> Event m Double
{-# INLINABLE enqueueStoreRate #-}
enqueueStoreRate :: Queue m si sm so a -> Event m Double
enqueueStoreRate Queue m si sm so a
q =
  (Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
x <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueStoreCountRef Queue m si sm so a
q)
     let t0 :: Double
t0 = Specs m -> Double
forall (m :: * -> *). Specs m -> Double
spcStartTime (Specs m -> Double) -> Specs m -> Double
forall a b. (a -> b) -> a -> b
$ Point m -> Specs m
forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
         t :: Double
t  = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0))
      
-- | Return the rate of the requests for dequeueing the items: how many requests
-- per time. It does not include the failed attempts to dequeue immediately
-- without suspension.
dequeueRate :: MonadDES m => Queue m si sm so a -> Event m Double
{-# INLINABLE dequeueRate #-}
dequeueRate :: Queue m si sm so a -> Event m Double
dequeueRate Queue m si sm so a
q =
  (Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
x <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
dequeueCountRef Queue m si sm so a
q)
     let t0 :: Double
t0 = Specs m -> Double
forall (m :: * -> *). Specs m -> Double
spcStartTime (Specs m -> Double) -> Specs m -> Double
forall a b. (a -> b) -> a -> b
$ Point m -> Specs m
forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
         t :: Double
t  = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0))
      
-- | Return the rate of the output items that were actually dequeued: how many items
-- per time.
dequeueExtractRate :: MonadDES m => Queue m si sm so a -> Event m Double
{-# INLINABLE dequeueExtractRate #-}
dequeueExtractRate :: Queue m si sm so a -> Event m Double
dequeueExtractRate Queue m si sm so a
q =
  (Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
x <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
dequeueExtractCountRef Queue m si sm so a
q)
     let t0 :: Double
t0 = Specs m -> Double
forall (m :: * -> *). Specs m -> Double
spcStartTime (Specs m -> Double) -> Specs m -> Double
forall a b. (a -> b) -> a -> b
$ Point m -> Specs m
forall (m :: * -> *). Point m -> Specs m
pointSpecs Point m
p
         t :: Double
t  = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0))
      
-- | Return the wait time from the time at which the item was stored in the queue to
-- the time at which it was dequeued.
--
-- See also 'queueWaitTimeChanged' and 'queueWaitTimeChanged_'.
queueWaitTime :: MonadDES m => Queue m si sm so a -> Event m (SamplingStats Double)
{-# INLINABLE queueWaitTime #-}
queueWaitTime :: Queue m si sm so a -> Event m (SamplingStats Double)
queueWaitTime Queue m si sm so a
q =
  (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (SamplingStats Double))
 -> Event m (SamplingStats Double))
-> (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
queueWaitTimeRef Queue m si sm so a
q)
      
-- | Signal when the 'queueWaitTime' property value has changed.
queueWaitTimeChanged :: MonadDES m => Queue m si sm so a -> Signal m (SamplingStats Double)
{-# INLINABLE queueWaitTimeChanged #-}
queueWaitTimeChanged :: Queue m si sm so a -> Signal m (SamplingStats Double)
queueWaitTimeChanged Queue m si sm so a
q =
  (() -> Event m (SamplingStats Double))
-> Signal m () -> Signal m (SamplingStats Double)
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
 -> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m (SamplingStats Double)
queueWaitTime Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
queueWaitTimeChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'queueWaitTime' property value has changed.
queueWaitTimeChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE queueWaitTimeChanged_ #-}
queueWaitTimeChanged_ :: Queue m si sm so a -> Signal m ()
queueWaitTimeChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q)
      
-- | Return the total wait time from the time at which the enqueueing operation
-- was initiated to the time at which the item was dequeued.
--
-- In some sense, @queueTotalWaitTime == enqueueWaitTime + queueWaitTime@.
--
-- See also 'queueTotalWaitTimeChanged' and 'queueTotalWaitTimeChanged_'.
queueTotalWaitTime :: MonadDES m => Queue m si sm so a -> Event m (SamplingStats Double)
{-# INLINABLE queueTotalWaitTime #-}
queueTotalWaitTime :: Queue m si sm so a -> Event m (SamplingStats Double)
queueTotalWaitTime Queue m si sm so a
q =
  (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (SamplingStats Double))
 -> Event m (SamplingStats Double))
-> (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
queueTotalWaitTimeRef Queue m si sm so a
q)
      
-- | Signal when the 'queueTotalWaitTime' property value has changed.
queueTotalWaitTimeChanged :: MonadDES m => Queue m si sm so a -> Signal m (SamplingStats Double)
{-# INLINABLE queueTotalWaitTimeChanged #-}
queueTotalWaitTimeChanged :: Queue m si sm so a -> Signal m (SamplingStats Double)
queueTotalWaitTimeChanged Queue m si sm so a
q =
  (() -> Event m (SamplingStats Double))
-> Signal m () -> Signal m (SamplingStats Double)
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
 -> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m (SamplingStats Double)
queueTotalWaitTime Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
queueTotalWaitTimeChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'queueTotalWaitTime' property value has changed.
queueTotalWaitTimeChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE queueTotalWaitTimeChanged_ #-}
queueTotalWaitTimeChanged_ :: Queue m si sm so a -> Signal m ()
queueTotalWaitTimeChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q)
      
-- | Return the enqueue wait time from the time at which the enqueueing operation
-- was initiated to the time at which the item was stored in the queue.
--
-- See also 'enqueueWaitTimeChanged' and 'enqueueWaitTimeChanged_'.
enqueueWaitTime :: MonadDES m => Queue m si sm so a -> Event m (SamplingStats Double)
{-# INLINABLE enqueueWaitTime #-}
enqueueWaitTime :: Queue m si sm so a -> Event m (SamplingStats Double)
enqueueWaitTime Queue m si sm so a
q =
  (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (SamplingStats Double))
 -> Event m (SamplingStats Double))
-> (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
enqueueWaitTimeRef Queue m si sm so a
q)
      
-- | Signal when the 'enqueueWaitTime' property value has changed.
enqueueWaitTimeChanged :: MonadDES m => Queue m si sm so a -> Signal m (SamplingStats Double)
{-# INLINABLE enqueueWaitTimeChanged #-}
enqueueWaitTimeChanged :: Queue m si sm so a -> Signal m (SamplingStats Double)
enqueueWaitTimeChanged Queue m si sm so a
q =
  (() -> Event m (SamplingStats Double))
-> Signal m () -> Signal m (SamplingStats Double)
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
 -> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m (SamplingStats Double)
enqueueWaitTime Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
enqueueWaitTimeChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'enqueueWaitTime' property value has changed.
enqueueWaitTimeChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE enqueueWaitTimeChanged_ #-}
enqueueWaitTimeChanged_ :: Queue m si sm so a -> Signal m ()
enqueueWaitTimeChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueStored Queue m si sm so a
q)
      
-- | Return the dequeue wait time from the time at which the item was requested
-- for dequeueing to the time at which it was actually dequeued.
--
-- See also 'dequeueWaitTimeChanged' and 'dequeueWaitTimeChanged_'.
dequeueWaitTime :: MonadDES m => Queue m si sm so a -> Event m (SamplingStats Double)
{-# INLINABLE dequeueWaitTime #-}
dequeueWaitTime :: Queue m si sm so a -> Event m (SamplingStats Double)
dequeueWaitTime Queue m si sm so a
q =
  (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (SamplingStats Double))
 -> Event m (SamplingStats Double))
-> (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
dequeueWaitTimeRef Queue m si sm so a
q)
      
-- | Signal when the 'dequeueWaitTime' property value has changed.
dequeueWaitTimeChanged :: MonadDES m => Queue m si sm so a -> Signal m (SamplingStats Double)
{-# INLINABLE dequeueWaitTimeChanged #-}
dequeueWaitTimeChanged :: Queue m si sm so a -> Signal m (SamplingStats Double)
dequeueWaitTimeChanged Queue m si sm so a
q =
  (() -> Event m (SamplingStats Double))
-> Signal m () -> Signal m (SamplingStats Double)
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
 -> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m (SamplingStats Double)
dequeueWaitTime Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
dequeueWaitTimeChanged_ Queue m si sm so a
q)
  
-- | Signal when the 'dequeueWaitTime' property value has changed.
dequeueWaitTimeChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE dequeueWaitTimeChanged_ #-}
dequeueWaitTimeChanged_ :: Queue m si sm so a -> Signal m ()
dequeueWaitTimeChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q)

-- | Return a long-term average queue rate calculated as
-- the average queue size divided by the average wait time.
--
-- This value may be less than the actual arrival rate as the queue is
-- finite and new arrivals may be locked while the queue remains full.
--
-- See also 'queueRateChanged' and 'queueRateChanged_'.
queueRate :: MonadDES m => Queue m si sm so a -> Event m Double
{-# INLINABLE queueRate #-}
queueRate :: Queue m si sm so a -> Event m Double
queueRate Queue m si sm so a
q =
  (Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do TimingStats Int
x <- Point m -> Event m (TimingStats Int) -> m (TimingStats Int)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (TimingStats Int) -> m (TimingStats Int))
-> Event m (TimingStats Int) -> m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> Event m (TimingStats Int)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m (TimingStats Int)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (TimingStats Int)
queueCountStatsRef Queue m si sm so a
q)
     SamplingStats Double
y <- Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
queueWaitTimeRef Queue m si sm so a
q)
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (TimingStats Int -> Double
forall a. TimingData a => TimingStats a -> Double
timingStatsMean TimingStats Int
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ SamplingStats Double -> Double
forall a. SamplingStats a -> Double
samplingStatsMean SamplingStats Double
y) 
      
-- | Signal when the 'queueRate' property value has changed.
queueRateChanged :: MonadDES m => Queue m si sm so a -> Signal m Double
{-# INLINABLE queueRateChanged #-}
queueRateChanged :: Queue m si sm so a -> Signal m Double
queueRateChanged Queue m si sm so a
q =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
queueRate Queue m si sm so a
q) (Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
queueRateChanged_ Queue m si sm so a
q)
      
-- | Signal when the 'queueRate' property value has changed.
queueRateChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE queueRateChanged_ #-}
queueRateChanged_ :: Queue m si sm so a -> Signal m ()
queueRateChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueStored Queue m si sm so a
q) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q)

-- | Dequeue suspending the process if the queue is empty.
dequeue :: (MonadDES m,
            DequeueStrategy m si,
            DequeueStrategy m sm,
            EnqueueStrategy m so)
           => Queue m si sm so a
           -- ^ the queue
           -> Process m a
           -- ^ the dequeued value
{-# INLINABLE dequeue #-}
dequeue :: Queue m si sm so a -> Process m a
dequeue Queue m si sm so a
q =
  do Double
t <- Event m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m Double -> Process m Double)
-> Event m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
dequeueRequest Queue m si sm so a
q
     Resource m so -> Process m ()
forall (m :: * -> *) s.
(MonadDES m, EnqueueStrategy m s) =>
Resource m s -> Process m ()
requestResource (Queue m si sm so a -> Resource m so
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m so
dequeueRes Queue m si sm so a
q)
     Event m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m a -> Process m a) -> Event m a -> Process m a
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Double -> Event m a
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DequeueStrategy m sm) =>
Queue m si sm so a -> Double -> Event m a
dequeueExtract Queue m si sm so a
q Double
t
  
-- | Dequeue with the output priority suspending the process if the queue is empty.
dequeueWithOutputPriority :: (MonadDES m,
                              DequeueStrategy m si,
                              DequeueStrategy m sm,
                              PriorityQueueStrategy m so po)
                             => Queue m si sm so a
                             -- ^ the queue
                             -> po
                             -- ^ the priority for output
                             -> Process m a
                             -- ^ the dequeued value
{-# INLINABLE dequeueWithOutputPriority #-}
dequeueWithOutputPriority :: Queue m si sm so a -> po -> Process m a
dequeueWithOutputPriority Queue m si sm so a
q po
po =
  do Double
t <- Event m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m Double -> Process m Double)
-> Event m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
dequeueRequest Queue m si sm so a
q
     Resource m so -> po -> Process m ()
forall (m :: * -> *) s p.
(MonadDES m, PriorityQueueStrategy m s p) =>
Resource m s -> p -> Process m ()
requestResourceWithPriority (Queue m si sm so a -> Resource m so
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m so
dequeueRes Queue m si sm so a
q) po
po
     Event m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m a -> Process m a) -> Event m a -> Process m a
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Double -> Event m a
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DequeueStrategy m sm) =>
Queue m si sm so a -> Double -> Event m a
dequeueExtract Queue m si sm so a
q Double
t
  
-- | Try to dequeue immediately.
tryDequeue :: (MonadDES m,
               DequeueStrategy m si,
               DequeueStrategy m sm)
              => Queue m si sm so a
              -- ^ the queue
              -> Event m (Maybe a)
              -- ^ the dequeued value of 'Nothing'
{-# INLINABLE tryDequeue #-}
tryDequeue :: Queue m si sm so a -> Event m (Maybe a)
tryDequeue Queue m si sm so a
q =
  do Bool
x <- Resource m so -> Event m Bool
forall (m :: * -> *) s. MonadDES m => Resource m s -> Event m Bool
tryRequestResourceWithinEvent (Queue m si sm so a -> Resource m so
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m so
dequeueRes Queue m si sm so a
q)
     if Bool
x 
       then do Double
t <- Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
dequeueRequest Queue m si sm so a
q
               (a -> Maybe a) -> Event m a -> Event m (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just (Event m a -> Event m (Maybe a)) -> Event m a -> Event m (Maybe a)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Double -> Event m a
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DequeueStrategy m sm) =>
Queue m si sm so a -> Double -> Event m a
dequeueExtract Queue m si sm so a
q Double
t
       else Maybe a -> Event m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing

-- | Remove the item from the queue and return a flag indicating
-- whether the item was found and actually removed.
queueDelete :: (MonadDES m,
                Eq a,
                DequeueStrategy m si,
                DeletingQueueStrategy m sm,
                DequeueStrategy m so)
               => Queue m si sm so a
               -- ^ the queue
               -> a
               -- ^ the item to remove from the queue
               -> Event m Bool
               -- ^ whether the item was found and removed
{-# INLINABLE queueDelete #-}
queueDelete :: Queue m si sm so a -> a -> Event m Bool
queueDelete Queue m si sm so a
q a
a = (Maybe a -> Bool) -> Event m (Maybe a) -> Event m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe a -> Bool
forall a. Maybe a -> Bool
isJust (Event m (Maybe a) -> Event m Bool)
-> Event m (Maybe a) -> Event m Bool
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DeletingQueueStrategy m sm,
 DequeueStrategy m so) =>
Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
queueDeleteBy Queue m si sm so a
q (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a)

-- | Remove the specified item from the queue.
queueDelete_ :: (MonadDES m,
                 Eq a,
                 DequeueStrategy m si,
                 DeletingQueueStrategy m sm,
                 DequeueStrategy m so)
                => Queue m si sm so a
                -- ^ the queue
                -> a
                -- ^ the item to remove from the queue
                -> Event m ()
{-# INLINABLE queueDelete_ #-}
queueDelete_ :: Queue m si sm so a -> a -> Event m ()
queueDelete_ Queue m si sm so a
q a
a = (Maybe a -> ()) -> Event m (Maybe a) -> Event m ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (() -> Maybe a -> ()
forall a b. a -> b -> a
const ()) (Event m (Maybe a) -> Event m ())
-> Event m (Maybe a) -> Event m ()
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DeletingQueueStrategy m sm,
 DequeueStrategy m so) =>
Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
queueDeleteBy Queue m si sm so a
q (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a)

-- | Remove an item satisfying the specified predicate and return the item if found.
queueDeleteBy :: (MonadDES m,
                  DequeueStrategy m si,
                  DeletingQueueStrategy m sm,
                  DequeueStrategy m so)
                 => Queue m si sm so a
                 -- ^ the queue
                 -> (a -> Bool)
                 -- ^ the predicate
                 -> Event m (Maybe a)
{-# INLINABLE queueDeleteBy #-}
queueDeleteBy :: Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
queueDeleteBy Queue m si sm so a
q a -> Bool
pred =
  do Bool
x <- Resource m so -> Event m Bool
forall (m :: * -> *) s. MonadDES m => Resource m s -> Event m Bool
tryRequestResourceWithinEvent (Queue m si sm so a -> Resource m so
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m so
dequeueRes Queue m si sm so a
q)
     if Bool
x
       then do Maybe (QueueItem a)
i <- StrategyQueue m sm (QueueItem a)
-> (QueueItem a -> Bool) -> Event m (Maybe (QueueItem a))
forall (m :: * -> *) s a.
DeletingQueueStrategy m s =>
StrategyQueue m s a -> (a -> Bool) -> Event m (Maybe a)
strategyQueueDeleteBy (Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
queueStore Queue m si sm so a
q) (a -> Bool
pred (a -> Bool) -> (QueueItem a -> a) -> QueueItem a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueueItem a -> a
forall a. QueueItem a -> a
itemValue)
               case Maybe (QueueItem a)
i of
                 Maybe (QueueItem a)
Nothing ->
                   do Resource m so -> Event m ()
forall (m :: * -> *) s.
(MonadDES m, DequeueStrategy m s) =>
Resource m s -> Event m ()
releaseResourceWithinEvent (Queue m si sm so a -> Resource m so
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m so
dequeueRes Queue m si sm so a
q)
                      Maybe a -> Event m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
                 Just QueueItem a
i ->
                   do Double
t <- Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
dequeueRequest Queue m si sm so a
q
                      (a -> Maybe a) -> Event m a -> Event m (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just (Event m a -> Event m (Maybe a)) -> Event m a -> Event m (Maybe a)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> Double -> QueueItem a -> Event m a
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DequeueStrategy m sm) =>
Queue m si sm so a -> Double -> QueueItem a -> Event m a
dequeuePostExtract Queue m si sm so a
q Double
t QueueItem a
i
       else Maybe a -> Event m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
               
-- | Remove an item satisfying the specified predicate.
queueDeleteBy_ :: (MonadDES m,
                   DequeueStrategy m si,
                   DeletingQueueStrategy m sm,
                   DequeueStrategy m so)
                  => Queue m si sm so a
                  -- ^ the queue
                  -> (a -> Bool)
                  -- ^ the predicate
                  -> Event m ()
{-# INLINABLE queueDeleteBy_ #-}
queueDeleteBy_ :: Queue m si sm so a -> (a -> Bool) -> Event m ()
queueDeleteBy_ Queue m si sm so a
q a -> Bool
pred = (Maybe a -> ()) -> Event m (Maybe a) -> Event m ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (() -> Maybe a -> ()
forall a b. a -> b -> a
const ()) (Event m (Maybe a) -> Event m ())
-> Event m (Maybe a) -> Event m ()
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DeletingQueueStrategy m sm,
 DequeueStrategy m so) =>
Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
queueDeleteBy Queue m si sm so a
q a -> Bool
pred

-- | Detect whether the item is contained in the queue.
queueContains :: (MonadDES m,
                  Eq a,
                  DeletingQueueStrategy m sm)
                 => Queue m si sm so a
                 -- ^ the queue
                 -> a
                 -- ^ the item to search the queue for
                 -> Event m Bool
                 -- ^ whether the item was found
{-# INLINABLE queueContains #-}
queueContains :: Queue m si sm so a -> a -> Event m Bool
queueContains Queue m si sm so a
q a
a = (Maybe a -> Bool) -> Event m (Maybe a) -> Event m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe a -> Bool
forall a. Maybe a -> Bool
isJust (Event m (Maybe a) -> Event m Bool)
-> Event m (Maybe a) -> Event m Bool
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
forall (m :: * -> *) sm si so a.
(MonadDES m, DeletingQueueStrategy m sm) =>
Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
queueContainsBy Queue m si sm so a
q (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a)

-- | Detect whether an item satisfying the specified predicate is contained in the queue.
queueContainsBy :: (MonadDES m,
                    DeletingQueueStrategy m sm)
                   => Queue m si sm so a
                   -- ^ the queue
                   -> (a -> Bool)
                   -- ^ the predicate
                   -> Event m (Maybe a)
                   -- ^ the item if it was found
{-# INLINABLE queueContainsBy #-}
queueContainsBy :: Queue m si sm so a -> (a -> Bool) -> Event m (Maybe a)
queueContainsBy Queue m si sm so a
q a -> Bool
pred =
  do Maybe (QueueItem a)
x <- StrategyQueue m sm (QueueItem a)
-> (QueueItem a -> Bool) -> Event m (Maybe (QueueItem a))
forall (m :: * -> *) s a.
DeletingQueueStrategy m s =>
StrategyQueue m s a -> (a -> Bool) -> Event m (Maybe a)
strategyQueueContainsBy (Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
queueStore Queue m si sm so a
q) (a -> Bool
pred (a -> Bool) -> (QueueItem a -> a) -> QueueItem a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueueItem a -> a
forall a. QueueItem a -> a
itemValue)
     case Maybe (QueueItem a)
x of
       Maybe (QueueItem a)
Nothing -> Maybe a -> Event m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
       Just QueueItem a
i  -> Maybe a -> Event m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> Event m (Maybe a)) -> Maybe a -> Event m (Maybe a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a
forall a. a -> Maybe a
Just (QueueItem a -> a
forall a. QueueItem a -> a
itemValue QueueItem a
i)

-- | Clear the queue immediately.
clearQueue :: (MonadDES m,
               DequeueStrategy m si,
               DequeueStrategy m sm)
              => Queue m si sm so a
              -- ^ the queue
              -> Event m ()
{-# INLINABLE clearQueue #-}
clearQueue :: Queue m si sm so a -> Event m ()
clearQueue Queue m si sm so a
q =
  do Maybe a
x <- Queue m si sm so a -> Event m (Maybe a)
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DequeueStrategy m sm) =>
Queue m si sm so a -> Event m (Maybe a)
tryDequeue Queue m si sm so a
q
     case Maybe a
x of
       Maybe a
Nothing -> () -> Event m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
       Just a
a  -> Queue m si sm so a -> Event m ()
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DequeueStrategy m sm) =>
Queue m si sm so a -> Event m ()
clearQueue Queue m si sm so a
q

-- | Enqueue the item suspending the process if the queue is full.  
enqueue :: (MonadDES m,
            EnqueueStrategy m si,
            EnqueueStrategy m sm,
            DequeueStrategy m so)
           => Queue m si sm so a
           -- ^ the queue
           -> a
           -- ^ the item to enqueue
           -> Process m ()
{-# INLINABLE enqueue #-}
enqueue :: Queue m si sm so a -> a -> Process m ()
enqueue Queue m si sm so a
q a
a =
  do QueueItem a
i <- Event m (QueueItem a) -> Process m (QueueItem a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m (QueueItem a) -> Process m (QueueItem a))
-> Event m (QueueItem a) -> Process m (QueueItem a)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> a -> Event m (QueueItem a)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m (QueueItem a)
enqueueInitiate Queue m si sm so a
q a
a
     Resource m si -> Process m ()
forall (m :: * -> *) s.
(MonadDES m, EnqueueStrategy m s) =>
Resource m s -> Process m ()
requestResource (Queue m si sm so a -> Resource m si
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m si
enqueueRes Queue m si sm so a
q)
     Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> QueueItem a -> Event m ()
forall (m :: * -> *) sm so si a.
(MonadDES m, EnqueueStrategy m sm, DequeueStrategy m so) =>
Queue m si sm so a -> QueueItem a -> Event m ()
enqueueStore Queue m si sm so a
q QueueItem a
i
     
-- | Enqueue with the input priority the item suspending the process if the queue is full.  
enqueueWithInputPriority :: (MonadDES m,
                             PriorityQueueStrategy m si pi,
                             EnqueueStrategy m sm,
                             DequeueStrategy m so)
                            => Queue m si sm so a
                            -- ^ the queue
                            -> pi
                            -- ^ the priority for input
                            -> a
                            -- ^ the item to enqueue
                            -> Process m ()
{-# INLINABLE enqueueWithInputPriority #-}
enqueueWithInputPriority :: Queue m si sm so a -> pi -> a -> Process m ()
enqueueWithInputPriority Queue m si sm so a
q pi
pi a
a =
  do QueueItem a
i <- Event m (QueueItem a) -> Process m (QueueItem a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m (QueueItem a) -> Process m (QueueItem a))
-> Event m (QueueItem a) -> Process m (QueueItem a)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> a -> Event m (QueueItem a)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m (QueueItem a)
enqueueInitiate Queue m si sm so a
q a
a
     Resource m si -> pi -> Process m ()
forall (m :: * -> *) s p.
(MonadDES m, PriorityQueueStrategy m s p) =>
Resource m s -> p -> Process m ()
requestResourceWithPriority (Queue m si sm so a -> Resource m si
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m si
enqueueRes Queue m si sm so a
q) pi
pi
     Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> QueueItem a -> Event m ()
forall (m :: * -> *) sm so si a.
(MonadDES m, EnqueueStrategy m sm, DequeueStrategy m so) =>
Queue m si sm so a -> QueueItem a -> Event m ()
enqueueStore Queue m si sm so a
q QueueItem a
i
     
-- | Enqueue with the storing priority the item suspending the process if the queue is full.  
enqueueWithStoringPriority :: (MonadDES m,
                               EnqueueStrategy m si,
                               PriorityQueueStrategy m sm pm,
                               DequeueStrategy m so)
                              => Queue m si sm so a
                              -- ^ the queue
                              -> pm
                              -- ^ the priority for storing
                              -> a
                              -- ^ the item to enqueue
                              -> Process m ()
{-# INLINABLE enqueueWithStoringPriority #-}
enqueueWithStoringPriority :: Queue m si sm so a -> pm -> a -> Process m ()
enqueueWithStoringPriority Queue m si sm so a
q pm
pm a
a =
  do QueueItem a
i <- Event m (QueueItem a) -> Process m (QueueItem a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m (QueueItem a) -> Process m (QueueItem a))
-> Event m (QueueItem a) -> Process m (QueueItem a)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> a -> Event m (QueueItem a)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m (QueueItem a)
enqueueInitiate Queue m si sm so a
q a
a
     Resource m si -> Process m ()
forall (m :: * -> *) s.
(MonadDES m, EnqueueStrategy m s) =>
Resource m s -> Process m ()
requestResource (Queue m si sm so a -> Resource m si
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m si
enqueueRes Queue m si sm so a
q)
     Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> pm -> QueueItem a -> Event m ()
forall (m :: * -> *) sm pm so si a.
(MonadDES m, PriorityQueueStrategy m sm pm,
 DequeueStrategy m so) =>
Queue m si sm so a -> pm -> QueueItem a -> Event m ()
enqueueStoreWithPriority Queue m si sm so a
q pm
pm QueueItem a
i
     
-- | Enqueue with the input and storing priorities the item suspending the process if the queue is full.  
enqueueWithInputStoringPriorities :: (MonadDES m,
                                      PriorityQueueStrategy m si pi,
                                      PriorityQueueStrategy m sm pm,
                                      DequeueStrategy m so)
                                     => Queue m si sm so a
                                     -- ^ the queue
                                     -> pi
                                     -- ^ the priority for input
                                     -> pm
                                     -- ^ the priority for storing
                                     -> a
                                     -- ^ the item to enqueue
                                     -> Process m ()
{-# INLINABLE enqueueWithInputStoringPriorities #-}
enqueueWithInputStoringPriorities :: Queue m si sm so a -> pi -> pm -> a -> Process m ()
enqueueWithInputStoringPriorities Queue m si sm so a
q pi
pi pm
pm a
a =
  do QueueItem a
i <- Event m (QueueItem a) -> Process m (QueueItem a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m (QueueItem a) -> Process m (QueueItem a))
-> Event m (QueueItem a) -> Process m (QueueItem a)
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> a -> Event m (QueueItem a)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m (QueueItem a)
enqueueInitiate Queue m si sm so a
q a
a
     Resource m si -> pi -> Process m ()
forall (m :: * -> *) s p.
(MonadDES m, PriorityQueueStrategy m s p) =>
Resource m s -> p -> Process m ()
requestResourceWithPriority (Queue m si sm so a -> Resource m si
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m si
enqueueRes Queue m si sm so a
q) pi
pi
     Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$ Queue m si sm so a -> pm -> QueueItem a -> Event m ()
forall (m :: * -> *) sm pm so si a.
(MonadDES m, PriorityQueueStrategy m sm pm,
 DequeueStrategy m so) =>
Queue m si sm so a -> pm -> QueueItem a -> Event m ()
enqueueStoreWithPriority Queue m si sm so a
q pm
pm QueueItem a
i
     
-- | Try to enqueue the item. Return 'False' in the monad if the queue is full.
tryEnqueue :: (MonadDES m,
               EnqueueStrategy m sm,
               DequeueStrategy m so)
              => Queue m si sm so a
              -- ^ the queue
              -> a
              -- ^ the item which we try to enqueue
              -> Event m Bool
{-# INLINABLE tryEnqueue #-}
tryEnqueue :: Queue m si sm so a -> a -> Event m Bool
tryEnqueue Queue m si sm so a
q a
a =
  do Bool
x <- Resource m si -> Event m Bool
forall (m :: * -> *) s. MonadDES m => Resource m s -> Event m Bool
tryRequestResourceWithinEvent (Queue m si sm so a -> Resource m si
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m si
enqueueRes Queue m si sm so a
q)
     if Bool
x 
       then do Queue m si sm so a -> a -> Event m (QueueItem a)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m (QueueItem a)
enqueueInitiate Queue m si sm so a
q a
a Event m (QueueItem a) -> (QueueItem a -> Event m ()) -> Event m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Queue m si sm so a -> QueueItem a -> Event m ()
forall (m :: * -> *) sm so si a.
(MonadDES m, EnqueueStrategy m sm, DequeueStrategy m so) =>
Queue m si sm so a -> QueueItem a -> Event m ()
enqueueStore Queue m si sm so a
q
               Bool -> Event m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
       else Bool -> Event m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False

-- | Try to enqueue with the storing priority the item. Return 'False' in
-- the monad if the queue is full.
tryEnqueueWithStoringPriority :: (MonadDES m,
                                  PriorityQueueStrategy m sm pm,
                                  DequeueStrategy m so)
                                 => Queue m si sm so a
                                 -- ^ the queue
                                 -> pm
                                 -- ^ the priority for storing
                                 -> a
                                 -- ^ the item which we try to enqueue
                                 -> Event m Bool
{-# INLINABLE tryEnqueueWithStoringPriority #-}
tryEnqueueWithStoringPriority :: Queue m si sm so a -> pm -> a -> Event m Bool
tryEnqueueWithStoringPriority Queue m si sm so a
q pm
pm a
a =
  do Bool
x <- Resource m si -> Event m Bool
forall (m :: * -> *) s. MonadDES m => Resource m s -> Event m Bool
tryRequestResourceWithinEvent (Queue m si sm so a -> Resource m si
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m si
enqueueRes Queue m si sm so a
q)
     if Bool
x 
       then do Queue m si sm so a -> a -> Event m (QueueItem a)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m (QueueItem a)
enqueueInitiate Queue m si sm so a
q a
a Event m (QueueItem a) -> (QueueItem a -> Event m ()) -> Event m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Queue m si sm so a -> pm -> QueueItem a -> Event m ()
forall (m :: * -> *) sm pm so si a.
(MonadDES m, PriorityQueueStrategy m sm pm,
 DequeueStrategy m so) =>
Queue m si sm so a -> pm -> QueueItem a -> Event m ()
enqueueStoreWithPriority Queue m si sm so a
q pm
pm
               Bool -> Event m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
       else Bool -> Event m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False

-- | Try to enqueue the item. If the queue is full then the item will be lost
-- and 'False' will be returned.
enqueueOrLost :: (MonadDES m,
                  EnqueueStrategy m sm,
                  DequeueStrategy m so)
                 => Queue m si sm so a
                 -- ^ the queue
                 -> a
                 -- ^ the item which we try to enqueue
                 -> Event m Bool
{-# INLINABLE enqueueOrLost #-}
enqueueOrLost :: Queue m si sm so a -> a -> Event m Bool
enqueueOrLost Queue m si sm so a
q a
a =
  do Bool
x <- Resource m si -> Event m Bool
forall (m :: * -> *) s. MonadDES m => Resource m s -> Event m Bool
tryRequestResourceWithinEvent (Queue m si sm so a -> Resource m si
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m si
enqueueRes Queue m si sm so a
q)
     if Bool
x
       then do Queue m si sm so a -> a -> Event m (QueueItem a)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m (QueueItem a)
enqueueInitiate Queue m si sm so a
q a
a Event m (QueueItem a) -> (QueueItem a -> Event m ()) -> Event m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Queue m si sm so a -> QueueItem a -> Event m ()
forall (m :: * -> *) sm so si a.
(MonadDES m, EnqueueStrategy m sm, DequeueStrategy m so) =>
Queue m si sm so a -> QueueItem a -> Event m ()
enqueueStore Queue m si sm so a
q
               Bool -> Event m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
       else do Queue m si sm so a -> a -> Event m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m ()
enqueueDeny Queue m si sm so a
q a
a
               Bool -> Event m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False

-- | Try to enqueue with the storing priority the item. If the queue is full
-- then the item will be lost and 'False' will be returned.
enqueueWithStoringPriorityOrLost :: (MonadDES m,
                                     PriorityQueueStrategy m sm pm,
                                     DequeueStrategy m so)
                                    => Queue m si sm so a
                                    -- ^ the queue
                                    -> pm
                                    -- ^ the priority for storing
                                    -> a
                                    -- ^ the item which we try to enqueue
                                    -> Event m Bool
{-# INLINABLE enqueueWithStoringPriorityOrLost #-}
enqueueWithStoringPriorityOrLost :: Queue m si sm so a -> pm -> a -> Event m Bool
enqueueWithStoringPriorityOrLost Queue m si sm so a
q pm
pm a
a =
  do Bool
x <- Resource m si -> Event m Bool
forall (m :: * -> *) s. MonadDES m => Resource m s -> Event m Bool
tryRequestResourceWithinEvent (Queue m si sm so a -> Resource m si
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m si
enqueueRes Queue m si sm so a
q)
     if Bool
x
       then do Queue m si sm so a -> a -> Event m (QueueItem a)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m (QueueItem a)
enqueueInitiate Queue m si sm so a
q a
a Event m (QueueItem a) -> (QueueItem a -> Event m ()) -> Event m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Queue m si sm so a -> pm -> QueueItem a -> Event m ()
forall (m :: * -> *) sm pm so si a.
(MonadDES m, PriorityQueueStrategy m sm pm,
 DequeueStrategy m so) =>
Queue m si sm so a -> pm -> QueueItem a -> Event m ()
enqueueStoreWithPriority Queue m si sm so a
q pm
pm
               Bool -> Event m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
       else do Queue m si sm so a -> a -> Event m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> a -> Event m ()
enqueueDeny Queue m si sm so a
q a
a
               Bool -> Event m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False

-- | Try to enqueue the item. If the queue is full then the item will be lost.
enqueueOrLost_ :: (MonadDES m,
                   EnqueueStrategy m sm,
                   DequeueStrategy m so)
                  => Queue m si sm so a
                  -- ^ the queue
                  -> a
                  -- ^ the item which we try to enqueue
                  -> Event m ()
{-# INLINABLE enqueueOrLost_ #-}
enqueueOrLost_ :: Queue m si sm so a -> a -> Event m ()
enqueueOrLost_ Queue m si sm so a
q a
a =
  do Bool
x <- Queue m si sm so a -> a -> Event m Bool
forall (m :: * -> *) sm so si a.
(MonadDES m, EnqueueStrategy m sm, DequeueStrategy m so) =>
Queue m si sm so a -> a -> Event m Bool
enqueueOrLost Queue m si sm so a
q a
a
     () -> Event m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Try to enqueue with the storing priority the item. If the queue is full
-- then the item will be lost.
enqueueWithStoringPriorityOrLost_ :: (MonadDES m,
                                      PriorityQueueStrategy m sm pm,
                                      DequeueStrategy m so)
                                     => Queue m si sm so a
                                     -- ^ the queue
                                     -> pm
                                     -- ^ the priority for storing
                                     -> a
                                     -- ^ the item which we try to enqueue
                                     -> Event m ()
{-# INLINABLE enqueueWithStoringPriorityOrLost_ #-}
enqueueWithStoringPriorityOrLost_ :: Queue m si sm so a -> pm -> a -> Event m ()
enqueueWithStoringPriorityOrLost_ Queue m si sm so a
q pm
pm a
a =
  do Bool
x <- Queue m si sm so a -> pm -> a -> Event m Bool
forall (m :: * -> *) sm pm so si a.
(MonadDES m, PriorityQueueStrategy m sm pm,
 DequeueStrategy m so) =>
Queue m si sm so a -> pm -> a -> Event m Bool
enqueueWithStoringPriorityOrLost Queue m si sm so a
q pm
pm a
a
     () -> Event m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Return a signal that notifies when the enqueuing operation is initiated.
enqueueInitiated :: MonadDES m => Queue m si sm so a -> Signal m a
{-# INLINABLE enqueueInitiated #-}
enqueueInitiated :: Queue m si sm so a -> Signal m a
enqueueInitiated Queue m si sm so a
q = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (Queue m si sm so a -> SignalSource m a
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m a
enqueueInitiatedSource Queue m si sm so a
q)

-- | Return a signal that notifies when the enqueuing operation is completed
-- and the item is stored in the internal memory of the queue.
enqueueStored :: MonadDES m => Queue m si sm so a -> Signal m a
{-# INLINABLE enqueueStored #-}
enqueueStored :: Queue m si sm so a -> Signal m a
enqueueStored Queue m si sm so a
q = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (Queue m si sm so a -> SignalSource m a
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m a
enqueueStoredSource Queue m si sm so a
q)

-- | Return a signal which notifies that the item was lost when 
-- attempting to add it to the full queue with help of
-- 'enqueueOrLost', 'enqueueOrLost_' or similar functions that imply
-- that the element can be lost. All their names are ending with @OrLost@
-- or @OrLost_@.
--
-- In other cases the enqueued items are not lost but the corresponded process
-- can suspend until the internal queue storage is freed. Although there is one
-- exception from this rule. If the process trying to enqueue a new element was
-- suspended but then canceled through 'cancelProcess' from the outside then
-- the item will not be added.
enqueueLost :: MonadDES m => Queue m si sm so a -> Signal m a
{-# INLINABLE enqueueLost #-}
enqueueLost :: Queue m si sm so a -> Signal m a
enqueueLost Queue m si sm so a
q = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (Queue m si sm so a -> SignalSource m a
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m a
enqueueLostSource Queue m si sm so a
q)

-- | Return a signal that notifies when the dequeuing operation was requested.
dequeueRequested :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE dequeueRequested #-}
dequeueRequested :: Queue m si sm so a -> Signal m ()
dequeueRequested Queue m si sm so a
q = SignalSource m () -> Signal m ()
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (Queue m si sm so a -> SignalSource m ()
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m ()
dequeueRequestedSource Queue m si sm so a
q)

-- | Return a signal that notifies when the item was extracted from the internal
-- storage of the queue and prepared for immediate receiving by the dequeuing process.
dequeueExtracted :: MonadDES m => Queue m si sm so a -> Signal m a
{-# INLINABLE dequeueExtracted #-}
dequeueExtracted :: Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (Queue m si sm so a -> SignalSource m a
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m a
dequeueExtractedSource Queue m si sm so a
q)

-- | Initiate the process of enqueuing the item.
enqueueInitiate :: MonadDES m
                   => Queue m si sm so a
                   -- ^ the queue
                   -> a
                   -- ^ the item to be enqueued
                   -> Event m (QueueItem a)
{-# INLINE enqueueInitiate #-}
enqueueInitiate :: Queue m si sm so a -> a -> Event m (QueueItem a)
enqueueInitiate Queue m si sm so a
q a
a =
  (Point m -> m (QueueItem a)) -> Event m (QueueItem a)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (QueueItem a)) -> Event m (QueueItem a))
-> (Point m -> m (QueueItem a)) -> Event m (QueueItem a)
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t :: Double
t = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> (Int -> Int) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueCountRef Queue m si sm so a
q) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Queue m si sm so a -> SignalSource m a
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m a
enqueueInitiatedSource Queue m si sm so a
q) a
a
     QueueItem a -> m (QueueItem a)
forall (m :: * -> *) a. Monad m => a -> m a
return QueueItem :: forall a. a -> Double -> Double -> QueueItem a
QueueItem { itemValue :: a
itemValue = a
a,
                        itemInputTime :: Double
itemInputTime = Double
t,
                        itemStoringTime :: Double
itemStoringTime = Double
t  -- it will be updated soon
                      }

-- | Store the item.
enqueueStore :: (MonadDES m,
                 EnqueueStrategy m sm,
                 DequeueStrategy m so)
                => Queue m si sm so a
                -- ^ the queue
                -> QueueItem a
                -- ^ the item to be stored
                -> Event m ()
{-# INLINE enqueueStore #-}
enqueueStore :: Queue m si sm so a -> QueueItem a -> Event m ()
enqueueStore Queue m si sm so a
q QueueItem a
i =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let i' :: QueueItem a
i' = QueueItem a
i { itemStoringTime :: Double
itemStoringTime = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p }  -- now we have the actual time of storing
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       StrategyQueue m sm (QueueItem a) -> QueueItem a -> Event m ()
forall (m :: * -> *) s a.
EnqueueStrategy m s =>
StrategyQueue m s a -> a -> Event m ()
strategyEnqueue (Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
queueStore Queue m si sm so a
q) QueueItem a
i'
     Int
c <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$
          Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q)
     let c' :: Int
c' = Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
         t :: Double
t  = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p 
     Int
c' Int -> m () -> m ()
`seq` Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q) Int
c'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (TimingStats Int)
-> (TimingStats Int -> TimingStats Int) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m (TimingStats Int)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (TimingStats Int)
queueCountStatsRef Queue m si sm so a
q) (Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats Double
t Int
c')
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> (Int -> Int) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueStoreCountRef Queue m si sm so a
q) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Queue m si sm so a -> QueueItem a -> Event m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> QueueItem a -> Event m ()
enqueueStat Queue m si sm so a
q QueueItem a
i'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Resource m so -> Event m ()
forall (m :: * -> *) s.
(MonadDES m, DequeueStrategy m s) =>
Resource m s -> Event m ()
releaseResourceWithinEvent (Queue m si sm so a -> Resource m so
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m so
dequeueRes Queue m si sm so a
q)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Queue m si sm so a -> SignalSource m a
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m a
enqueueStoredSource Queue m si sm so a
q) (QueueItem a -> a
forall a. QueueItem a -> a
itemValue QueueItem a
i')

-- | Store with the priority the item.
enqueueStoreWithPriority :: (MonadDES m,
                             PriorityQueueStrategy m sm pm,
                             DequeueStrategy m so)
                            => Queue m si sm so a
                            -- ^ the queue
                            -> pm
                            -- ^ the priority for storing
                            -> QueueItem a
                            -- ^ the item to be enqueued
                            -> Event m ()
{-# INLINE enqueueStoreWithPriority #-}
enqueueStoreWithPriority :: Queue m si sm so a -> pm -> QueueItem a -> Event m ()
enqueueStoreWithPriority Queue m si sm so a
q pm
pm QueueItem a
i =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let i' :: QueueItem a
i' = QueueItem a
i { itemStoringTime :: Double
itemStoringTime = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p }  -- now we have the actual time of storing
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       StrategyQueue m sm (QueueItem a) -> pm -> QueueItem a -> Event m ()
forall (m :: * -> *) s p a.
PriorityQueueStrategy m s p =>
StrategyQueue m s a -> p -> a -> Event m ()
strategyEnqueueWithPriority (Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
queueStore Queue m si sm so a
q) pm
pm QueueItem a
i'
     Int
c <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$
          Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q)
     let c' :: Int
c' = Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
         t :: Double
t  = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Int
c' Int -> m () -> m ()
`seq` Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q) Int
c'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (TimingStats Int)
-> (TimingStats Int -> TimingStats Int) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m (TimingStats Int)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (TimingStats Int)
queueCountStatsRef Queue m si sm so a
q) (Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats Double
t Int
c')
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> (Int -> Int) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueStoreCountRef Queue m si sm so a
q) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Queue m si sm so a -> QueueItem a -> Event m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> QueueItem a -> Event m ()
enqueueStat Queue m si sm so a
q QueueItem a
i'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Resource m so -> Event m ()
forall (m :: * -> *) s.
(MonadDES m, DequeueStrategy m s) =>
Resource m s -> Event m ()
releaseResourceWithinEvent (Queue m si sm so a -> Resource m so
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m so
dequeueRes Queue m si sm so a
q)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Queue m si sm so a -> SignalSource m a
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m a
enqueueStoredSource Queue m si sm so a
q) (QueueItem a -> a
forall a. QueueItem a -> a
itemValue QueueItem a
i')

-- | Deny the enqueuing.
enqueueDeny :: MonadDES m
               => Queue m si sm so a
               -- ^ the queue
               -> a
               -- ^ the item to be denied
               -> Event m ()
{-# INLINE enqueueDeny #-}
enqueueDeny :: Queue m si sm so a -> a -> Event m ()
enqueueDeny Queue m si sm so a
q a
a =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> (Int -> Int) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueLostCountRef Queue m si sm so a
q) ((Int -> Int) -> Event m ()) -> (Int -> Int) -> Event m ()
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) Int
1
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Queue m si sm so a -> SignalSource m a
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m a
enqueueLostSource Queue m si sm so a
q) a
a

-- | Update the statistics for the input wait time of the enqueuing operation.
enqueueStat :: MonadDES m
               => Queue m si sm so a
               -- ^ the queue
               -> QueueItem a
               -- ^ the item and its input time
               -> Event m ()
               -- ^ the action of updating the statistics
{-# INLINE enqueueStat #-}
enqueueStat :: Queue m si sm so a -> QueueItem a -> Event m ()
enqueueStat Queue m si sm so a
q QueueItem a
i =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t0 :: Double
t0 = QueueItem a -> Double
forall a. QueueItem a -> Double
itemInputTime QueueItem a
i
         t1 :: Double
t1 = QueueItem a -> Double
forall a. QueueItem a -> Double
itemStoringTime QueueItem a
i
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
enqueueWaitTimeRef Queue m si sm so a
q) ((SamplingStats Double -> SamplingStats Double) -> Event m ())
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)

-- | Accept the dequeuing request and return the current simulation time.
dequeueRequest :: MonadDES m
                  => Queue m si sm so a
                  -- ^ the queue
                  -> Event m Double
                  -- ^ the current time
{-# INLINE dequeueRequest #-}
dequeueRequest :: Queue m si sm so a -> Event m Double
dequeueRequest Queue m si sm so a
q =
  (Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> (Int -> Int) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
dequeueCountRef Queue m si sm so a
q) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m () -> () -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Queue m si sm so a -> SignalSource m ()
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m ()
dequeueRequestedSource Queue m si sm so a
q) ()
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> m Double) -> Double -> m Double
forall a b. (a -> b) -> a -> b
$ Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p 

-- | Extract an item for the dequeuing request.  
dequeueExtract :: (MonadDES m,
                   DequeueStrategy m si,
                   DequeueStrategy m sm)
                  => Queue m si sm so a
                  -- ^ the queue
                  -> Double
                  -- ^ the time of the dequeuing request
                  -> Event m a
                  -- ^ the dequeued value
{-# INLINE dequeueExtract #-}
dequeueExtract :: Queue m si sm so a -> Double -> Event m a
dequeueExtract Queue m si sm so a
q Double
t' =
  (Point m -> m a) -> Event m a
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m a) -> Event m a) -> (Point m -> m a) -> Event m a
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do QueueItem a
i <- Point m -> Event m (QueueItem a) -> m (QueueItem a)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (QueueItem a) -> m (QueueItem a))
-> Event m (QueueItem a) -> m (QueueItem a)
forall a b. (a -> b) -> a -> b
$
          StrategyQueue m sm (QueueItem a) -> Event m (QueueItem a)
forall (m :: * -> *) s a.
DequeueStrategy m s =>
StrategyQueue m s a -> Event m a
strategyDequeue (Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> StrategyQueue m sm (QueueItem a)
queueStore Queue m si sm so a
q)
     Point m -> Event m a -> m a
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m a -> m a) -> Event m a -> m a
forall a b. (a -> b) -> a -> b
$
       Queue m si sm so a -> Double -> QueueItem a -> Event m a
forall (m :: * -> *) si sm so a.
(MonadDES m, DequeueStrategy m si, DequeueStrategy m sm) =>
Queue m si sm so a -> Double -> QueueItem a -> Event m a
dequeuePostExtract Queue m si sm so a
q Double
t' QueueItem a
i

-- | A post action after extracting the item by the dequeuing request.  
dequeuePostExtract :: (MonadDES m,
                       DequeueStrategy m si,
                       DequeueStrategy m sm)
                      => Queue m si sm so a
                      -- ^ the queue
                      -> Double
                      -- ^ the time of the dequeuing request
                      -> QueueItem a
                      -- ^ the item to dequeue
                      -> Event m a
                      -- ^ the dequeued value
{-# INLINE dequeuePostExtract #-}
dequeuePostExtract :: Queue m si sm so a -> Double -> QueueItem a -> Event m a
dequeuePostExtract Queue m si sm so a
q Double
t' QueueItem a
i =
  (Point m -> m a) -> Event m a
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m a) -> Event m a) -> (Point m -> m a) -> Event m a
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
c <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$
          Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q)
     let c' :: Int
c' = Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
         t :: Double
t  = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Int
c' Int -> m () -> m ()
`seq` Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q) Int
c'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (TimingStats Int)
-> (TimingStats Int -> TimingStats Int) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m (TimingStats Int)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (TimingStats Int)
queueCountStatsRef Queue m si sm so a
q) (Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats Double
t Int
c')
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> (Int -> Int) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
dequeueExtractCountRef Queue m si sm so a
q) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Queue m si sm so a -> Double -> QueueItem a -> Event m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Double -> QueueItem a -> Event m ()
dequeueStat Queue m si sm so a
q Double
t' QueueItem a
i
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Resource m si -> Event m ()
forall (m :: * -> *) s.
(MonadDES m, DequeueStrategy m s) =>
Resource m s -> Event m ()
releaseResourceWithinEvent (Queue m si sm so a -> Resource m si
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Resource m si
enqueueRes Queue m si sm so a
q)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Queue m si sm so a -> SignalSource m a
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> SignalSource m a
dequeueExtractedSource Queue m si sm so a
q) (QueueItem a -> a
forall a. QueueItem a -> a
itemValue QueueItem a
i)
     a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> m a) -> a -> m a
forall a b. (a -> b) -> a -> b
$ QueueItem a -> a
forall a. QueueItem a -> a
itemValue QueueItem a
i

-- | Update the statistics for the output wait time of the dequeuing operation
-- and the wait time of storing in the queue.
dequeueStat :: MonadDES m
               => Queue m si sm so a
               -- ^ the queue
               -> Double
               -- ^ the time of the dequeuing request
               -> QueueItem a
               -- ^ the item and its input time
               -> Event m ()
               -- ^ the action of updating the statistics
{-# INLINE dequeueStat #-}
dequeueStat :: Queue m si sm so a -> Double -> QueueItem a -> Event m ()
dequeueStat Queue m si sm so a
q Double
t' QueueItem a
i =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t0 :: Double
t0 = QueueItem a -> Double
forall a. QueueItem a -> Double
itemInputTime QueueItem a
i
         t1 :: Double
t1 = QueueItem a -> Double
forall a. QueueItem a -> Double
itemStoringTime QueueItem a
i
         t :: Double
t  = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
dequeueWaitTimeRef Queue m si sm so a
q) ((SamplingStats Double -> SamplingStats Double) -> Event m ())
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t')
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
queueTotalWaitTimeRef Queue m si sm so a
q) ((SamplingStats Double -> SamplingStats Double) -> Event m ())
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
queueWaitTimeRef Queue m si sm so a
q) ((SamplingStats Double -> SamplingStats Double) -> Event m ())
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t1)

-- | Wait while the queue is full.
waitWhileFullQueue :: MonadDES m => Queue m si sm so a -> Process m ()
{-# INLINABLE waitWhileFullQueue #-}
waitWhileFullQueue :: Queue m si sm so a -> Process m ()
waitWhileFullQueue Queue m si sm so a
q =
  do Bool
x <- Event m Bool -> Process m Bool
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Queue m si sm so a -> Event m Bool
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Bool
queueFull Queue m si sm so a
q)
     Bool -> Process m () -> Process m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
x (Process m () -> Process m ()) -> Process m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
       do Signal m a -> Process m a
forall (m :: * -> *) a. MonadDES m => Signal m a -> Process m a
processAwait (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q)
          Queue m si sm so a -> Process m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Process m ()
waitWhileFullQueue Queue m si sm so a
q

-- | Signal whenever any property of the queue changes.
--
-- The property must have the corresponded signal. There are also characteristics
-- similar to the properties but that have no signals. As a rule, such characteristics
-- already depend on the simulation time and therefore they may change at any
-- time point.
queueChanged_ :: MonadDES m => Queue m si sm so a -> Signal m ()
{-# INLINABLE queueChanged_ #-}
queueChanged_ :: Queue m si sm so a -> Signal m ()
queueChanged_ Queue m si sm so a
q =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueInitiated Queue m si sm so a
q) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueStored Queue m si sm so a
q) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
enqueueLost Queue m si sm so a
q) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  Queue m si sm so a -> Signal m ()
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m ()
dequeueRequested Queue m si sm so a
q Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Queue m si sm so a -> Signal m a
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Signal m a
dequeueExtracted Queue m si sm so a
q)

-- | Return the summary for the queue with desciption of its
-- properties and activities using the specified indent.
queueSummary :: (MonadDES m, Show si, Show sm, Show so) => Queue m si sm so a -> Int -> Event m ShowS
{-# INLINABLE queueSummary #-}
queueSummary :: Queue m si sm so a -> Int -> Event m ShowS
queueSummary Queue m si sm so a
q Int
indent =
  do let si :: si
si = Queue m si sm so a -> si
forall (m :: * -> *) si sm so a. Queue m si sm so a -> si
enqueueStrategy Queue m si sm so a
q
         sm :: sm
sm = Queue m si sm so a -> sm
forall (m :: * -> *) si sm so a. Queue m si sm so a -> sm
enqueueStoringStrategy Queue m si sm so a
q
         so :: so
so = Queue m si sm so a -> so
forall (m :: * -> *) si sm so a. Queue m si sm so a -> so
dequeueStrategy Queue m si sm so a
q
     Bool
null <- Queue m si sm so a -> Event m Bool
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Bool
queueNull Queue m si sm so a
q
     Bool
full <- Queue m si sm so a -> Event m Bool
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Bool
queueFull Queue m si sm so a
q
     let maxCount :: Int
maxCount = Queue m si sm so a -> Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Int
queueMaxCount Queue m si sm so a
q
     Int
count <- Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
queueCount Queue m si sm so a
q
     TimingStats Int
countStats <- Queue m si sm so a -> Event m (TimingStats Int)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m (TimingStats Int)
queueCountStats Queue m si sm so a
q
     Int
enqueueCount <- Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
enqueueCount Queue m si sm so a
q
     Int
enqueueLostCount <- Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
enqueueLostCount Queue m si sm so a
q
     Int
enqueueStoreCount <- Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
enqueueStoreCount Queue m si sm so a
q
     Int
dequeueCount <- Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
dequeueCount Queue m si sm so a
q
     Int
dequeueExtractCount <- Queue m si sm so a -> Event m Int
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Int
dequeueExtractCount Queue m si sm so a
q
     Double
loadFactor <- Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
queueLoadFactor Queue m si sm so a
q
     Double
enqueueRate <- Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
enqueueRate Queue m si sm so a
q
     Double
enqueueStoreRate <- Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
enqueueStoreRate Queue m si sm so a
q
     Double
dequeueRate <- Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
dequeueRate Queue m si sm so a
q
     Double
dequeueExtractRate <- Queue m si sm so a -> Event m Double
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m Double
dequeueExtractRate Queue m si sm so a
q
     SamplingStats Double
waitTime <- Queue m si sm so a -> Event m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m (SamplingStats Double)
queueWaitTime Queue m si sm so a
q
     SamplingStats Double
totalWaitTime <- Queue m si sm so a -> Event m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m (SamplingStats Double)
queueTotalWaitTime Queue m si sm so a
q
     SamplingStats Double
enqueueWaitTime <- Queue m si sm so a -> Event m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m (SamplingStats Double)
enqueueWaitTime Queue m si sm so a
q
     SamplingStats Double
dequeueWaitTime <- Queue m si sm so a -> Event m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
MonadDES m =>
Queue m si sm so a -> Event m (SamplingStats Double)
dequeueWaitTime Queue m si sm so a
q
     let tab :: [Char]
tab = Int -> Char -> [Char]
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     ShowS -> Event m ShowS
forall (m :: * -> *) a. Monad m => a -> m a
return (ShowS -> Event m ShowS) -> ShowS -> Event m ShowS
forall a b. (a -> b) -> a -> b
$
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the enqueueing (input) strategy = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       si -> ShowS
forall a. Show a => a -> ShowS
shows si
si ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the storing (memory) strategy = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       sm -> ShowS
forall a. Show a => a -> ShowS
shows sm
sm ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the dequeueing (output) strategy = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       so -> ShowS
forall a. Show a => a -> ShowS
shows so
so ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"empty? = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Bool -> ShowS
forall a. Show a => a -> ShowS
shows Bool
null ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"full? = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Bool -> ShowS
forall a. Show a => a -> ShowS
shows Bool
full ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"max. capacity = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
maxCount ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"size = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
count ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the size statistics = \n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       TimingStats Int -> Int -> ShowS
forall a. (Show a, TimingData a) => TimingStats a -> Int -> ShowS
timingStatsSummary TimingStats Int
countStats (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the enqueue count (number of the input items that were enqueued) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
enqueueCount ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the enqueue lost count (number of the lost items) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
enqueueLostCount ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the enqueue store count (number of the input items that were stored) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
enqueueStoreCount ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the dequeue count (number of requests for dequeueing an item) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
dequeueCount ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the dequeue extract count (number of the output items that were dequeued) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
dequeueExtractCount ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the load factor (size / max. capacity) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
loadFactor ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the enqueue rate (how many input items were enqueued per time) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
enqueueRate ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the enqueue store rate (how many input items were stored per time) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
enqueueStoreRate ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the dequeue rate (how many requests for dequeueing per time) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
dequeueRate ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the dequeue extract rate (how many output items were dequeued per time) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
dequeueExtractRate ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the wait time (when was stored -> when was dequeued) = \n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
waitTime (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the total wait time (when the enqueueing was initiated -> when was dequeued) = \n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
totalWaitTime (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the enqueue wait time (when the enqueueing was initiated -> when was stored) = \n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
enqueueWaitTime (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"the dequeue wait time (when was requested for dequeueing -> when was dequeued) = \n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
dequeueWaitTime (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent)

-- | Reset the statistics.
resetQueue :: MonadDES m => Queue m si sm so a -> Event m ()
{-# INLINABLE resetQueue #-}
resetQueue :: Queue m si sm so a -> Event m ()
resetQueue Queue m si sm so a
q =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t :: Double
t = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Int
queueCount <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
queueCountRef Queue m si sm so a
q)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> TimingStats Int -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m (TimingStats Int)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (TimingStats Int)
queueCountStatsRef Queue m si sm so a
q) (TimingStats Int -> Event m ()) -> TimingStats Int -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
queueCount
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueCountRef Queue m si sm so a
q) Int
0
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueLostCountRef Queue m si sm so a
q) Int
0
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
enqueueStoreCountRef Queue m si sm so a
q) Int
0
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
dequeueCountRef Queue m si sm so a
q) Int
0
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m Int
forall (m :: * -> *) si sm so a. Queue m si sm so a -> Ref m Int
dequeueExtractCountRef Queue m si sm so a
q) Int
0
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
queueWaitTimeRef Queue m si sm so a
q) SamplingStats Double
forall a. Monoid a => a
mempty
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
queueTotalWaitTimeRef Queue m si sm so a
q) SamplingStats Double
forall a. Monoid a => a
mempty
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
enqueueWaitTimeRef Queue m si sm so a
q) SamplingStats Double
forall a. Monoid a => a
mempty
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Queue m si sm so a -> Ref m (SamplingStats Double)
forall (m :: * -> *) si sm so a.
Queue m si sm so a -> Ref m (SamplingStats Double)
dequeueWaitTimeRef Queue m si sm so a
q) SamplingStats Double
forall a. Monoid a => a
mempty