PriorityChansConverger-0.1: Read single output from an array of inputs - channels with priorities

Control.Concurrent.PriorityChansConverger.PriorityChansConverger

Contents

Description

This module wraps STM PCC with IO. Some locks are added to balance heavyweight transactions, to reduce "waste efforts".

Synopsis

PriorityChansConverger ADT and it's administration

data Ord k => PriorityChansConverger k e Source

Wrapper around PriorityChansConvergerSTM. Added locks. Show instance is defined using unsafePerformIO.

newPriorityChansConverger_wCUIS :: Ord k => Maybe ConcurrentUISupport -> Map k (StartPriority, ChanCapacity) -> IO (PriorityChansConverger k e)Source

Wrapper around newPriorityChansConvergerSTM_wCUIS constructor. With an option to enable utility ConcurrentUISupport (which is useful for debugging)

lockPCC :: Ord k => LockUserName -> [PCC_Lock] -> PriorityChansConverger k e -> IO ()Source

Sort the locks and lock them.

WARNING !!! Asynchronous exceptions may cause loss of locks!

unlockPCC :: Ord k => LockUserName -> [PCC_Lock] -> PriorityChansConverger k e -> IO ()Source

Reverse sort the locks and unlock them.

WARNING !!! Asynchronous exceptions may cause loss of locks!

withLockedDo :: Ord k => LockUserName -> [PCC_Lock] -> PriorityChansConverger k e -> IO a -> IO aSource

Locking IO action wrapper.

WARNING !!! Asynchronous exceptions may cause loss of locks!

PriorityChansConverger mutation

PriorityChansConverger I/O

writeInPCC :: Ord k => PermitToBlock -> k -> e -> PriorityChansConverger k e -> IO (Maybe FailureReasonWPCC)Source

Wrapper around writeInPCC_STM. Used locks: if blocking, then [] else [PCC_Lock].

If blocking is enabled, may block, when there is no free space in PriorityChan.

stmInterruptableWriteInPCC :: Ord k => STM InterruptShouldWe -> k -> e -> PriorityChansConverger k e -> IO (Either () (Maybe FailureReasonWPCC))Source

Wrapper around interruptableWriteInPCC_STM. Used locks: []

Blocking write.

Do not put the control of the STM InterruptShouldWe under PCC_Lock. Keep there False, if you don't want to get Left () in return. Put there True, whenever you want to stop waiting.

interruptableWriteInPCC :: Ord k => (Chan a, a -> InterruptShouldWe) -> k -> e -> PriorityChansConverger k e -> IO (Either () (Maybe FailureReasonWPCC))Source

Wrapper around stmInterruptableWriteInPCC. Used locks: [PCC_IOInterruptableWrite]

Blocking read.

Creates a TVar Bool to control the interruptability of write operation. Spawns additional thread, which cyclicly reads given Chan and checks, if it signals terminating condition - if so, then using interrupter TVar stops trying to write in PCC. Temporary thread gets terminated at the end.

readFromPCC :: Ord k => PermitToBlock -> PriorityChansConverger k e -> IO (Maybe (k, e))Source

Wrapper around readFromPCC_STM. Used locks: if blocking, then [] else [PCC_Lock].

stmInterruptableReadFromPCC :: Ord k => STM InterruptShouldWe -> PriorityChansConverger k e -> IO (Either () (k, e))Source

Wrapper around interruptableReadFromPCC_STM. Used locks: []

Blocking read.

interruptableReadFromPCC :: Ord k => (Chan a, a -> InterruptShouldWe) -> PriorityChansConverger k e -> IO (Either () (k, e))Source

Wrapper around stmInterruptableReadFromPCC. Used locks: [PCC_IOInterruptableRead]

Blocking read.

Creates a TVar Bool to control the interruptability of read operation. Spawns additional thread, which cyclicly reads given Chan and checks, if it signals terminating condition - if so, then using interrupter TVar stops trying to write in PCC. Temporary thread gets terminated at the end.

flushPCC2List :: Ord k => PriorityChansConverger k e -> IO [(k, e)]Source

Wrapper around flushPCC2List_STM. Used locks: [PCC_Lock]

Lazy (doublecheck that).

flushPCC2List' :: Ord k => PriorityChansConverger k e -> IO [(k, e)]Source

Wrapper around flushPCC2List_STM' (see Control.Concurrent.PriorityChansConverger.PriorityChansConverger). Used locks: [PCC_Lock]

Strict. Should be a bit faster than flushPCC2List.

fastFlushPCC2List' :: Ord k => PriorityChansConverger k e -> IO [(k, e)]Source

Wrapper around fastFlushPCC2List_STM' (see Control.Concurrent.PriorityChansConverger.PriorityChansConverger). Used locks: [PCC_Lock]

Strict. This is a fast flush, it doesn't deal with priorities.

isEmptyPCC :: Ord k => PriorityChansConverger k e -> IO BoolSource

Wrapper around isEmptyPCC_STM. Used locks: none

filterOutPCCElements' :: Ord k => PriorityChansConverger k e -> (e -> TakeElementOutShouldWe) -> IO [(k, e)]Source

Wrapper around filterOutPCCElements_STM' (see Control.Concurrent.PriorityChansConverger.PriorityChansConverger). Used locks: [PCC_Lock]

Strict.

Take everything, applu filter, return what's left in the PCC, return what's taken out.

PriorityChansConverger representation

showPCC :: (Ord k, Show k, Show e) => PriorityChansConverger k e -> IO StringSource

Wrapper around showPCC. Used locks: none