hunt-searchengine-0.3.0.1: A search and indexing engine.

Safe HaskellSafe-Inferred
LanguageHaskell98

Control.Concurrent.XMVar

Description

An MVar variation that only blocks for modification. Readers are never blocked but write access is carried out in sequence.

This is done with two MVars. While modification is done, the readers use the old value. When the modification is done, the old (unmodified) value is replaced with the new one. For this to work, the writers have to block each other which is done with the second MVar. This process is encapsulated in modifyXMVar and modifyXMVar_.

Note: This may increase the memory usage since there may be two value present at a time. This is intended to be used with (big) data structures where small changes are made.

Synopsis

Documentation

data XMVar a Source

An MVar variation that only blocks for modification. It consists of two MVars. One for the value which can always be read and the second one to block writers so that modifications are done sequentially.

newXMVar :: a -> IO (XMVar a) Source

Create a new XMVar with the supplied value.

readXMVar :: XMVar a -> IO a Source

Read the value.

modifyXMVar :: XMVar a -> (a -> IO (a, b)) -> IO b Source

Modify the content.

modifyXMVar_ :: XMVar a -> (a -> IO a) -> IO () Source

Like modifyXMVar but without a return value.

takeXMVarWrite :: XMVar a -> IO a Source

Locks for writes and reads the value. Readers do not block each other. modifyXMVar encapsulates takeXMVarWrite and putXMVarWrite and also handles exceptions.

putXMVarWrite :: XMVar a -> a -> IO () Source

Replaces the value (since it was locked for potential writers) and unlocks writers.

takeXMVarLock :: XMVar a -> IO a Source

Locks for both reads and writes (MVar behaviour). This may be useful to save space because the old a does not have to be kept in memory for read access. Note that references to the old a might still lead to memory leaks/issues.

putXMVarLock :: XMVar a -> a -> IO () Source

Replaces the value (since it was locked for potential writers) and unlocks writers.