dejafu-0.3.2.0: Overloadable primitives for testable, potentially non-deterministic, concurrency.

Copyright (c) 2016 Michael Walker MIT Michael Walker stable portable None Haskell2010

Control.Concurrent.Classy.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.

Deviations: TBQueue as defined here does not have an Eq instance, this is because the MonadSTM TVar type does not have an Eq constraint. Furthermore, the newTBQueueIO function is not provided.

Synopsis

# TBQueue

data TBQueue stm a Source #

TBQueue is an abstract type representing a bounded FIFO channel.

Arguments

 :: MonadSTM stm => Int maximum number of elements the queue can hold -> stm (TBQueue stm a)

Build and returns a new instance of TBQueue

readTBQueue :: MonadSTM stm => TBQueue stm a -> stm a Source #

Read the next value from the TBQueue.

tryReadTBQueue :: MonadSTM stm => TBQueue stm a -> stm (Maybe a) Source #

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

peekTBQueue :: MonadSTM stm => TBQueue stm a -> stm a Source #

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

tryPeekTBQueue :: MonadSTM stm => TBQueue stm a -> stm (Maybe a) Source #

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

writeTBQueue :: MonadSTM stm => TBQueue stm a -> a -> stm () Source #

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

unGetTBQueue :: MonadSTM stm => TBQueue stm 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.

isEmptyTBQueue :: MonadSTM stm => TBQueue stm a -> stm Bool Source #

Returns True if the supplied TBQueue is empty.

isFullTBQueue :: MonadSTM stm => TBQueue stm a -> stm Bool Source #

Returns True if the supplied TBQueue is full.