gang-of-threads-3.2.1: Non-deterministic parallelism with bags

PortabilityPOSIX
Stabilityexperimental
Maintainerbastianholst@gmx.de
Safe HaskellSafe-Inferred

Control.Concurrent.Bag.TaskBufferSTM

Description

This module contains the definition of a task buffer in the STM monad, TaskBufferSTM, and possible split functions besides the functions to create a Stack and a Queue buffer.

Synopsis

Documentation

data TaskBufferSTM a Source

A buffer holding tasks.

For this type, all access functions are using the STM monad.

Note, that this is not a type class because we want to allow the user to select between multiple buffers other than on type level.

Constructors

TaskBufferSTM 

Fields

writeBufferSTM :: a -> STM ()

Function to write an item into the buffer in the normal way.

unGetBufferSTM :: a -> STM ()

Function to write an item into the buffer at the read end.

readBufferSTM :: STM a

Function to read item from the buffer. Blocks if empty.

tryReadBufferSTM :: STM (Maybe a)

Function to try to read an item from the buffer. Returns Nothing if empty.

isEmptyBufferSTM :: STM Bool

Check whether the buffer is empty.

data BufferType Source

The type of a buffer. At this time you can only select between Queue and Stack.

Constructors

Queue

A first in first out (FIFO) buffer.

Stack

A last in first out (LIFO) buffer.

type SplitFunction r = TaskBufferSTM (IO (Maybe r)) -> TaskBufferSTM (IO (Maybe r)) -> STM (IO (Maybe r))Source

Split functions are used to split the contents of the source buffer into two parts. One part is left in this buffer or put back later; the other part is written into the sink buffer. One element of this part is returned in the STM monad. This is why the source buffer should always have at least one item available. If it has not, the action will suspend.

takeFirst :: SplitFunction rSource

Just take the first item from the source buffer.

splitVertical :: SplitFunction rSource

Split the buffer vertically. Every other element of the source remains there. All other elements are put into the sink buffer.

splitHalf :: SplitFunction rSource

Split the buffer in two halves. Takes one half out of the source buffer and puts it into the sink buffer.

newChanBufferSTM :: STM (TaskBufferSTM r)Source

Create a new Queue buffer from a TChan.

newStackBufferSTM :: STM (TaskBufferSTM r)Source

Create a new Stack buffer from a TStack.