stm-2.5.2.1: Software Transactional Memory
Copyright(c) The University of Glasgow 2012
LicenseBSD-style (see the file libraries/base/LICENSE)
Maintainerlibraries@haskell.org
Stabilityexperimental
Portabilitynon-portable (requires STM)
Safe HaskellTrustworthy
LanguageHaskell2010

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 retries until an element is removed from the queue.

The implementation is based on an array to obtain O(1) enqueue and dequeue operations.

Since: 2.4

Synopsis

TBQueue

data TBQueue a Source #

TBQueue is an abstract type representing a bounded FIFO channel.

Since: 2.4

Instances

Instances details
Eq (TBQueue a) Source # 
Instance details

Defined in Control.Concurrent.STM.TBQueue

Methods

(==) :: TBQueue a -> TBQueue a -> Bool #

(/=) :: TBQueue a -> TBQueue a -> Bool #

newTBQueue Source #

Arguments

:: Natural

maximum number of elements the queue can hold

-> STM (TBQueue a) 

Builds and returns a new instance of TBQueue.

newTBQueueIO :: Natural -> 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 a Source #

Read the next value from the TBQueue; retries if the queue is empty.

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

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

flushTBQueue :: forall a. TBQueue a -> STM [a] Source #

Efficiently read the entire contents of a TBQueue into a list. This function never retries.

Since: 2.4.5

peekTBQueue :: TBQueue a -> STM a Source #

Get the next value from the TBQueue without removing it, retrying if the queue 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; retries 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. Retries if the queue is full.

lengthTBQueue :: TBQueue a -> STM Natural Source #

Return the length of a TBQueue.

Since: 2.5.0.0

isEmptyTBQueue :: TBQueue a -> STM Bool Source #

Returns True if the supplied TBQueue is empty.

isFullTBQueue :: TBQueue a -> STM Bool Source #

Returns True if the supplied TBQueue is full.

Since: 2.4.3

capacityTBQueue :: TBQueue a -> Natural Source #

The maximum number of elements the queue can hold.

@since TODO