Control.Concurrent.STM.TBQueue

stm-2.4.4: Software Transactional Memory

Copyright | (c) The University of Glasgow 2012
License | BSD-style (see the file libraries/base/LICENSE)
Maintainer | libraries@haskell.org
Stability | experimental
Portability | non-portable (requires STM)
Safe Haskell | Trustworthy
Language | Haskell98

Control.Concurrent.STM.TBQueue

Contents

- TBQueue

Description

`TBQueue` is a bounded version of `TQueue`. The queue has a maximum capacity set when it is created. If the queue already contains the maximum number of elements, then `writeTBQueue` blocks until an element is removed from the queue.

The implementation is based on the traditional purely-functional queue representation that uses two lists to obtain amortised O(1) enqueue and dequeue operations.

Since: 2.4

Synopsis

- data TBQueue a
- newTBQueue :: Int -> STM (TBQueue a)
- newTBQueueIO :: Int -> IO (TBQueue a)
- readTBQueue :: TBQueue a -> STM a
- tryReadTBQueue :: TBQueue a -> STM (Maybe a)
- peekTBQueue :: TBQueue a -> STM a
- tryPeekTBQueue :: TBQueue a -> STM (Maybe a)
- writeTBQueue :: TBQueue a -> a -> STM ()
- unGetTBQueue :: TBQueue a -> a -> STM ()
- isEmptyTBQueue :: TBQueue a -> STM Bool
- isFullTBQueue :: TBQueue a -> STM Bool

# TBQueue

data TBQueue a

`TBQueue` is an abstract type representing a bounded FIFO channel.

Since: 2.4

Instances

Eq (TBQueue a) |

newTBQueue

Arguments

:: Int | maximum number of elements the queue can hold
-> STM (TBQueue a) |

Build and returns a new instance of `TBQueue`

newTBQueueIO :: Int -> IO (TBQueue a)

`IO` version of `newTBQueue`. This is useful for creating top-level `TBQueue`s using `unsafePerformIO`, because using `atomically` inside `unsafePerformIO` isn't possible.

readTBQueue :: TBQueue a -> STM a

Read the next value from the `TBQueue`.

tryReadTBQueue :: TBQueue a -> STM (Maybe a)

A version of `readTBQueue` which does not retry. Instead it returns `Nothing` if no value is available.

peekTBQueue :: TBQueue a -> STM a

Get the next value from the `TBQueue` without removing it, retrying if the channel is empty.

tryPeekTBQueue :: TBQueue a -> STM (Maybe a)

A version of `peekTBQueue` which does not retry. Instead it returns `Nothing` if no value is available.

writeTBQueue :: TBQueue a -> a -> STM ()

Write a value to a `TBQueue`; blocks if the queue is full.

unGetTBQueue :: TBQueue a -> a -> STM ()

Put a data item back onto a channel, where it will be the next item read. Blocks if the queue is full.

isEmptyTBQueue :: TBQueue a -> STM Bool

Returns `True` if the supplied `TBQueue` is empty.

isFullTBQueue :: TBQueue a -> STM Bool

Returns `True` if the supplied `TBQueue` is full.

Since: 2.4.3