kazura-queue-0.1.0.4: Fast concurrent queues much inspired by unagi-chan

Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.WVar

Contents

Description

WVar is waitable IORef. It is similar to MVar but different at some points.

  • The latest (cached) value can be read while someone is updating the value.
  • Put operation can overwrite the value if the value is fresh and cannot be blocked for waiting empty.
  • WVar is strict. It means that the new value storing into the WVar will be evaluated (WHNF) before actual storing.

There are two states in the user viewpoint.

Fresh
The WVar is not being updated. This state corresponds to full state of MVar.
Updating
The WVar is being updated by someone. This state corresponds to empty state of MVar. However, cached previous value can be read while Updating.
Synopsis

WVar

Main functions of WVar.

data WVar a Source #

"a" is the type of data in the WVar.

Instances
Eq (WVar a) Source # 
Instance details

Defined in Control.Concurrent.WVar

Methods

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

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

newWVar :: a -> IO (WVar a) Source #

Create a fresh WVar that contains the supplied value.

takeWVar :: WVar a -> IO a Source #

Take the value of a WVar like takeMVar. It blocks when the WVar is being updated.

tryTakeWVar :: WVar a -> IO (Bool, a) Source #

Non-blocking version of takeWVar.

putWVar :: WVar a -> a -> IO () Source #

Put the supplied value into a WVar. It performs simple "write" when the WVar is Fresh. When the supplied value is already evaluated, it never blocks.

readWVar :: WVar a -> IO a Source #

Read the cached value of the WVar. It never blocks.

readFreshWVar :: WVar a -> IO a Source #

Read the fresh value of the WVar. It blocks and waits for a fresh value when the WVar is being updated by someone.

tryReadFreshWVar :: WVar a -> IO (Bool, a) Source #

Non-blocking version of readFreshWVar

WCached

Low level types and functions of WVar.

data WCached a Source #

WCached consists of WVar and its cached ticket.

Constructors

WCached 

Fields

Instances
Eq (WCached a) Source # 
Instance details

Defined in Control.Concurrent.WVar

Methods

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

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

Show a => Show (WCached a) Source # 
Instance details

Defined in Control.Concurrent.WVar

Methods

showsPrec :: Int -> WCached a -> ShowS #

show :: WCached a -> String #

showList :: [WCached a] -> ShowS #

type WTicket a = Ticket (WContent a) Source #

cacheWVar :: WVar a -> IO (WCached a) Source #

Cache the current value of the WVar and create WCached.

recacheWCached :: WCached a -> IO (WCached a) Source #

Recache the WCached.

recacheWCached = cacheWVar . cachedVar

readWTicket :: WTicket a -> a Source #

Read the value of the WTicket

takeWCached :: WCached a -> IO (WTicket a) Source #

Take the value of the WCached like takeMVar. It blocks when the WCached is being updated.

tryTakeWCached :: WCached a -> IO (Bool, WTicket a) Source #

Non-blocking version of takeWCached.

putWCached :: WCached a -> a -> IO (WTicket a) Source #

Put the value to the WCached. It performs simple "write" when the WVar is Fresh. When the supplied value is already evaluated, it never blocks.

tryPutWCached :: WCached a -> a -> IO (Bool, WTicket a) Source #

Put the value to a WCached. It performs simple "write" when the WVar is Fresh. It fails when the cache is obsoleted. When the supplied value is already evaluated, it never blocks.

readWCached :: WCached a -> a Source #

Read the cached value of the WCached. It never blocks.

readFreshWCached :: WCached a -> IO (WTicket a) Source #

Read the Fresh value of the WCached. It blocks and waits for a Fresh value when the WCached is being updated by someone.

tryReadFreshWCached :: WCached a -> IO (Bool, WTicket a) Source #

Non-blocking version of readFreshWCached