{-# LANGUAGE BangPatterns       #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE GADTs              #-}
{-# LANGUAGE TypeOperators      #-}

-- | This module corresponds to `Control.Concurrent.STM.TBQueue` in "stm" package
--
module Control.Concurrent.Class.MonadSTM.Strict.TBQueue
  ( -- * MonadSTM
    StrictTBQueue
  , LazyTBQueue
  , toLazyTBQueue
  , fromLazyTBQueue
  , castStrictTBQueue
  , newTBQueue
  , newTBQueueIO
  , readTBQueue
  , tryReadTBQueue
  , peekTBQueue
  , tryPeekTBQueue
  , flushTBQueue
  , writeTBQueue
  , lengthTBQueue
  , isEmptyTBQueue
  , isFullTBQueue
  , unGetTBQueue
    -- * MonadLabelledSTM
  , labelTBQueue
  , labelTBQueueIO
    -- * MonadTraceSTM
  , traceTBQueue
  , traceTBQueueIO
  ) where


import qualified Control.Concurrent.Class.MonadSTM.TBQueue as Lazy
import           Control.Monad.Class.MonadSTM hiding (traceTBQueue, traceTBQueueIO)

import           Numeric.Natural (Natural)


type LazyTBQueue m = Lazy.TBQueue m

newtype StrictTBQueue m a = StrictTBQueue { forall (m :: * -> *) a. StrictTBQueue m a -> LazyTBQueue m a
toLazyTBQueue :: LazyTBQueue m a }

fromLazyTBQueue :: LazyTBQueue m a -> StrictTBQueue m a
fromLazyTBQueue :: forall (m :: * -> *) a. LazyTBQueue m a -> StrictTBQueue m a
fromLazyTBQueue = forall (m :: * -> *) a. LazyTBQueue m a -> StrictTBQueue m a
StrictTBQueue

castStrictTBQueue :: LazyTBQueue m ~ LazyTBQueue n
                  => StrictTBQueue m a -> StrictTBQueue n a
castStrictTBQueue :: forall (m :: * -> *) (n :: * -> *) a.
(LazyTBQueue m ~ LazyTBQueue n) =>
StrictTBQueue m a -> StrictTBQueue n a
castStrictTBQueue (StrictTBQueue LazyTBQueue m a
var) = forall (m :: * -> *) a. LazyTBQueue m a -> StrictTBQueue m a
StrictTBQueue LazyTBQueue m a
var

labelTBQueue :: MonadLabelledSTM m => StrictTBQueue m a -> String -> STM m ()
labelTBQueue :: forall (m :: * -> *) a.
MonadLabelledSTM m =>
StrictTBQueue m a -> String -> STM m ()
labelTBQueue (StrictTBQueue LazyTBQueue m a
queue) = forall (m :: * -> *) a.
MonadLabelledSTM m =>
TBQueue m a -> String -> STM m ()
Lazy.labelTBQueue LazyTBQueue m a
queue

labelTBQueueIO :: MonadLabelledSTM m => StrictTBQueue m a -> String -> m ()
labelTBQueueIO :: forall (m :: * -> *) a.
MonadLabelledSTM m =>
StrictTBQueue m a -> String -> m ()
labelTBQueueIO (StrictTBQueue LazyTBQueue m a
queue) = forall (m :: * -> *) a.
MonadLabelledSTM m =>
TBQueue m a -> String -> m ()
Lazy.labelTBQueueIO LazyTBQueue m a
queue

traceTBQueue :: MonadTraceSTM m
             => proxy m
             -> StrictTBQueue m a
             -> ((Maybe [a]) -> [a] -> InspectMonad m TraceValue)
             -> STM m ()
traceTBQueue :: forall (m :: * -> *) (proxy :: (* -> *) -> *) a.
MonadTraceSTM m =>
proxy m
-> StrictTBQueue m a
-> (Maybe [a] -> [a] -> InspectMonad m TraceValue)
-> STM m ()
traceTBQueue proxy m
p (StrictTBQueue LazyTBQueue m a
queue) = forall (m :: * -> *) (proxy :: (* -> *) -> *) a.
MonadTraceSTM m =>
proxy m
-> TBQueue m a
-> (Maybe [a] -> [a] -> InspectMonad m TraceValue)
-> STM m ()
Lazy.traceTBQueue proxy m
p LazyTBQueue m a
queue

traceTBQueueIO :: MonadTraceSTM m
               => StrictTBQueue m a
               -> ((Maybe [a]) -> [a] -> InspectMonad m TraceValue)
               -> m ()
traceTBQueueIO :: forall (m :: * -> *) a.
MonadTraceSTM m =>
StrictTBQueue m a
-> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m ()
traceTBQueueIO (StrictTBQueue LazyTBQueue m a
queue) = forall (m :: * -> *) a.
MonadTraceSTM m =>
TBQueue m a
-> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m ()
Lazy.traceTBQueueIO LazyTBQueue m a
queue

newTBQueue :: MonadSTM m => Natural -> STM m (StrictTBQueue m a)
newTBQueue :: forall (m :: * -> *) a.
MonadSTM m =>
Natural -> STM m (StrictTBQueue m a)
newTBQueue Natural
n = forall (m :: * -> *) a. LazyTBQueue m a -> StrictTBQueue m a
StrictTBQueue forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
MonadSTM m =>
Natural -> STM m (TBQueue m a)
Lazy.newTBQueue Natural
n

newTBQueueIO :: MonadSTM m => Natural -> m (StrictTBQueue m a)
newTBQueueIO :: forall (m :: * -> *) a.
MonadSTM m =>
Natural -> m (StrictTBQueue m a)
newTBQueueIO = forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
MonadSTM m =>
Natural -> STM m (StrictTBQueue m a)
newTBQueue

readTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m a
readTBQueue :: forall (m :: * -> *) a. MonadSTM m => StrictTBQueue m a -> STM m a
readTBQueue = forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m a
Lazy.readTBQueue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StrictTBQueue m a -> LazyTBQueue m a
toLazyTBQueue

tryReadTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m (Maybe a)
tryReadTBQueue :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTBQueue m a -> STM m (Maybe a)
tryReadTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueue m a -> STM m (Maybe a)
Lazy.tryReadTBQueue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StrictTBQueue m a -> LazyTBQueue m a
toLazyTBQueue

peekTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m a
peekTBQueue :: forall (m :: * -> *) a. MonadSTM m => StrictTBQueue m a -> STM m a
peekTBQueue = forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m a
Lazy.peekTBQueue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StrictTBQueue m a -> LazyTBQueue m a
toLazyTBQueue

tryPeekTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m (Maybe a)
tryPeekTBQueue :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTBQueue m a -> STM m (Maybe a)
tryPeekTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueue m a -> STM m (Maybe a)
Lazy.tryPeekTBQueue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StrictTBQueue m a -> LazyTBQueue m a
toLazyTBQueue

flushTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m [a]
flushTBQueue :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTBQueue m a -> STM m [a]
flushTBQueue = forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m [a]
Lazy.flushTBQueue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StrictTBQueue m a -> LazyTBQueue m a
toLazyTBQueue

writeTBQueue :: MonadSTM m => StrictTBQueue m a -> a -> STM m ()
writeTBQueue :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTBQueue m a -> a -> STM m ()
writeTBQueue (StrictTBQueue LazyTBQueue m a
tqueue) !a
a = forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> a -> STM m ()
Lazy.writeTBQueue LazyTBQueue m a
tqueue a
a

lengthTBQueue  :: MonadSTM m => StrictTBQueue m a -> STM m Natural
lengthTBQueue :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTBQueue m a -> STM m Natural
lengthTBQueue = forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m Natural
Lazy.lengthTBQueue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StrictTBQueue m a -> LazyTBQueue m a
toLazyTBQueue

isEmptyTBQueue  :: MonadSTM m => StrictTBQueue m a -> STM m Bool
isEmptyTBQueue :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTBQueue m a -> STM m Bool
isEmptyTBQueue = forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m Bool
Lazy.isEmptyTBQueue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StrictTBQueue m a -> LazyTBQueue m a
toLazyTBQueue

isFullTBQueue  :: MonadSTM m => StrictTBQueue m a -> STM m Bool
isFullTBQueue :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTBQueue m a -> STM m Bool
isFullTBQueue = forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m Bool
Lazy.isFullTBQueue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StrictTBQueue m a -> LazyTBQueue m a
toLazyTBQueue

unGetTBQueue :: MonadSTM m => StrictTBQueue m a -> a -> STM m ()
unGetTBQueue :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTBQueue m a -> a -> STM m ()
unGetTBQueue (StrictTBQueue LazyTBQueue m a
queue) !a
a = forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> a -> STM m ()
Lazy.unGetTBQueue LazyTBQueue m a
queue a
a