stm-2.4.2: Software Transactional Memory

Portabilitynon-portable (requires STM)
Stabilityexperimental
Maintainerlibraries@haskell.org
Safe HaskellTrustworthy

Control.Concurrent.STM.TBQueue

Contents

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.

Synopsis

TBQueue

data TBQueue a Source

TBQueue is an abstract type representing a bounded FIFO channel.

Instances

newTBQueueSource

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)Source

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

readTBQueue :: TBQueue a -> STM aSource

Read the next value from the TBQueue.

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

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

peekTBQueue :: TBQueue a -> STM aSource

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

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

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

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

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

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

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 BoolSource

Returns True if the supplied TBQueue is empty.