hls-graph-1.9.0.0: Haskell Language Server internal graph API
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Concurrent.STM.Stats

Synopsis

Documentation

registerDelay :: Int -> IO (TVar Bool) #

Switch the value of returned TVar from initial value False to True after a given number of microseconds. The caveats associated with threadDelay also apply.

data TVar a #

Shared memory locations that support atomic memory transactions.

Instances

Instances details
Eq (TVar a)

Since: base-4.8.0.0

Instance details

Defined in GHC.Conc.Sync

Methods

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

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

data STM a #

A monad supporting atomic memory transactions.

Instances

Instances details
Alternative STM

Since: base-4.8.0.0

Instance details

Defined in GHC.Conc.Sync

Methods

empty :: STM a #

(<|>) :: STM a -> STM a -> STM a #

some :: STM a -> STM [a] #

many :: STM a -> STM [a] #

Applicative STM

Since: base-4.8.0.0

Instance details

Defined in GHC.Conc.Sync

Methods

pure :: a -> STM a #

(<*>) :: STM (a -> b) -> STM a -> STM b #

liftA2 :: (a -> b -> c) -> STM a -> STM b -> STM c #

(*>) :: STM a -> STM b -> STM b #

(<*) :: STM a -> STM b -> STM a #

Functor STM

Since: base-4.3.0.0

Instance details

Defined in GHC.Conc.Sync

Methods

fmap :: (a -> b) -> STM a -> STM b #

(<$) :: a -> STM b -> STM a #

Monad STM

Since: base-4.3.0.0

Instance details

Defined in GHC.Conc.Sync

Methods

(>>=) :: STM a -> (a -> STM b) -> STM b #

(>>) :: STM a -> STM b -> STM b #

return :: a -> STM a #

MonadPlus STM

Since: base-4.3.0.0

Instance details

Defined in GHC.Conc.Sync

Methods

mzero :: STM a #

mplus :: STM a -> STM a -> STM a #

MonadCatch STM 
Instance details

Defined in Control.Monad.Catch

Methods

catch :: Exception e => STM a -> (e -> STM a) -> STM a #

MonadThrow STM 
Instance details

Defined in Control.Monad.Catch

Methods

throwM :: Exception e => e -> STM a #

MonadBaseControl STM STM 
Instance details

Defined in Control.Monad.Trans.Control

Associated Types

type StM STM a #

Methods

liftBaseWith :: (RunInBase STM STM -> STM a) -> STM a #

restoreM :: StM STM a -> STM a #

MArray TArray e STM 
Instance details

Defined in Control.Concurrent.STM.TArray

Methods

getBounds :: Ix i => TArray i e -> STM (i, i) #

getNumElements :: Ix i => TArray i e -> STM Int

newArray :: Ix i => (i, i) -> e -> STM (TArray i e) #

newArray_ :: Ix i => (i, i) -> STM (TArray i e) #

unsafeNewArray_ :: Ix i => (i, i) -> STM (TArray i e)

unsafeRead :: Ix i => TArray i e -> Int -> STM e

unsafeWrite :: Ix i => TArray i e -> Int -> e -> STM ()

RandomGen g => FrozenGen (TGen g) STM

Since: random-1.2.1

Instance details

Defined in System.Random.Stateful

Associated Types

type MutableGen (TGen g) STM = (g :: Type) #

Methods

freezeGen :: MutableGen (TGen g) STM -> STM (TGen g) #

thawGen :: TGen g -> STM (MutableGen (TGen g) STM) #

RandomGen g => StatefulGen (TGenM g) STM

Since: random-1.2.1

Instance details

Defined in System.Random.Stateful

RandomGen r => RandomGenM (TGenM r) r STM 
Instance details

Defined in System.Random.Stateful

Methods

applyRandomGenM :: (r -> (a, r)) -> TGenM r -> STM a #

type StM STM a 
Instance details

Defined in Control.Monad.Trans.Control

type StM STM a = a
type MutableGen (TGen g) STM 
Instance details

Defined in System.Random.Stateful

type MutableGen (TGen g) STM = TGenM g

writeTVar :: TVar a -> a -> STM () #

Write the supplied value into a TVar.

throwSTM :: Exception e => e -> STM a #

A variant of throw that can only be used within the STM monad.

Throwing an exception in STM aborts the transaction and propagates the exception. If the exception is caught via catchSTM, only the changes enclosed by the catch are rolled back; changes made outside of catchSTM persist.

If the exception is not caught inside of the STM, it is re-thrown by atomically, and the entire STM is rolled back.

Although throwSTM has a type that is an instance of the type of throw, the two functions are subtly different:

throw e    `seq` x  ===> throw e
throwSTM e `seq` x  ===> x

The first example will cause the exception e to be raised, whereas the second one won't. In fact, throwSTM will only cause an exception to be raised when it is used within the STM monad. The throwSTM variant should be used in preference to throw to raise an exception within the STM monad because it guarantees ordering with respect to other STM operations, whereas throw does not.

retry :: STM a #

Retry execution of the current memory transaction because it has seen values in TVars which mean that it should not continue (e.g. the TVars represent a shared buffer that is now empty). The implementation may block the thread until one of the TVars that it has read from has been updated. (GHC only)

readTVarIO :: TVar a -> IO a #

Return the current value stored in a TVar. This is equivalent to

 readTVarIO = atomically . readTVar

but works much faster, because it doesn't perform a complete transaction, it just reads the current value of the TVar.

readTVar :: TVar a -> STM a #

Return the current value stored in a TVar.

orElse :: STM a -> STM a -> STM a #

Compose two alternative STM actions (GHC only).

If the first action completes without retrying then it forms the result of the orElse. Otherwise, if the first action retries, then the second action is tried in its place. If both actions retry then the orElse as a whole retries.

newTVarIO :: a -> IO (TVar a) #

IO version of newTVar. This is useful for creating top-level TVars using unsafePerformIO, because using atomically inside unsafePerformIO isn't possible.

newTVar :: a -> STM (TVar a) #

Create a new TVar holding a value supplied

catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a #

Exception handling within STM actions.

catchSTM m f catches any exception thrown by m using throwSTM, using the function f to handle the exception. If an exception is thrown, any changes made by m are rolled back, but changes prior to m persist.

check :: Bool -> STM () #

Check that the boolean condition is true and, if not, retry.

In other words, check b = unless b retry.

Since: stm-2.1.1

data TArray i e #

TArray is a transactional array, supporting the usual MArray interface for mutable arrays.

It is currently implemented as Array ix (TVar e), but it may be replaced by a more efficient implementation in the future (the interface will remain the same, however).

Instances

Instances details
MArray TArray e STM 
Instance details

Defined in Control.Concurrent.STM.TArray

Methods

getBounds :: Ix i => TArray i e -> STM (i, i) #

getNumElements :: Ix i => TArray i e -> STM Int

newArray :: Ix i => (i, i) -> e -> STM (TArray i e) #

newArray_ :: Ix i => (i, i) -> STM (TArray i e) #

unsafeNewArray_ :: Ix i => (i, i) -> STM (TArray i e)

unsafeRead :: Ix i => TArray i e -> Int -> STM e

unsafeWrite :: Ix i => TArray i e -> Int -> e -> STM ()

Ix i => Eq (TArray i e) 
Instance details

Defined in Control.Concurrent.STM.TArray

Methods

(==) :: TArray i e -> TArray i e -> Bool #

(/=) :: TArray i e -> TArray i e -> Bool #

swapTVar :: TVar a -> a -> STM a #

Swap the contents of a TVar for a new value.

Since: stm-2.3

stateTVar :: TVar s -> (s -> (a, s)) -> STM a #

Like modifyTVar' but the function is a simple state transition that can return a side value which is passed on as the result of the STM.

Since: stm-2.5.0

modifyTVar' :: TVar a -> (a -> a) -> STM () #

Strict version of modifyTVar.

Since: stm-2.3

modifyTVar :: TVar a -> (a -> a) -> STM () #

Mutate the contents of a TVar. N.B., this version is non-strict.

Since: stm-2.3

mkWeakTVar :: TVar a -> IO () -> IO (Weak (TVar a)) #

Make a Weak pointer to a TVar, using the second argument as a finalizer to run when TVar is garbage-collected

Since: stm-2.4.3

data TQueue a #

TQueue is an abstract type representing an unbounded FIFO channel.

Since: stm-2.4

Instances

Instances details
Eq (TQueue a) 
Instance details

Defined in Control.Concurrent.STM.TQueue

Methods

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

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

writeTQueue :: TQueue a -> a -> STM () #

Write a value to a TQueue.

unGetTQueue :: TQueue a -> a -> STM () #

Put a data item back onto a channel, where it will be the next item read.

tryReadTQueue :: TQueue a -> STM (Maybe a) #

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

tryPeekTQueue :: TQueue a -> STM (Maybe a) #

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

readTQueue :: TQueue a -> STM a #

Read the next value from the TQueue.

peekTQueue :: TQueue a -> STM a #

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

newTQueueIO :: IO (TQueue a) #

IO version of newTQueue. This is useful for creating top-level TQueues using unsafePerformIO, because using atomically inside unsafePerformIO isn't possible.

newTQueue :: STM (TQueue a) #

Build and returns a new instance of TQueue

isEmptyTQueue :: TQueue a -> STM Bool #

Returns True if the supplied TQueue is empty.

flushTQueue :: TQueue a -> STM [a] #

Efficiently read the entire contents of a TQueue into a list. This function never retries.

Since: stm-2.4.5

data TMVar a #

A TMVar is a synchronising variable, used for communication between concurrent threads. It can be thought of as a box, which may be empty or full.

Instances

Instances details
Eq (TMVar a) 
Instance details

Defined in Control.Concurrent.STM.TMVar

Methods

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

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

tryTakeTMVar :: TMVar a -> STM (Maybe a) #

A version of takeTMVar that does not retry. The tryTakeTMVar function returns Nothing if the TMVar was empty, or Just a if the TMVar was full with contents a. After tryTakeTMVar, the TMVar is left empty.

tryReadTMVar :: TMVar a -> STM (Maybe a) #

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

Since: stm-2.3

tryPutTMVar :: TMVar a -> a -> STM Bool #

A version of putTMVar that does not retry. The tryPutTMVar function attempts to put the value a into the TMVar, returning True if it was successful, or False otherwise.

takeTMVar :: TMVar a -> STM a #

Return the contents of the TMVar. If the TMVar is currently empty, the transaction will retry. After a takeTMVar, the TMVar is left empty.

swapTMVar :: TMVar a -> a -> STM a #

Swap the contents of a TMVar for a new value.

readTMVar :: TMVar a -> STM a #

This is a combination of takeTMVar and putTMVar; ie. it takes the value from the TMVar, puts it back, and also returns it.

putTMVar :: TMVar a -> a -> STM () #

Put a value into a TMVar. If the TMVar is currently full, putTMVar will retry.

newTMVarIO :: a -> IO (TMVar a) #

IO version of newTMVar. This is useful for creating top-level TMVars using unsafePerformIO, because using atomically inside unsafePerformIO isn't possible.

newTMVar :: a -> STM (TMVar a) #

Create a TMVar which contains the supplied value.

newEmptyTMVarIO :: IO (TMVar a) #

IO version of newEmptyTMVar. This is useful for creating top-level TMVars using unsafePerformIO, because using atomically inside unsafePerformIO isn't possible.

newEmptyTMVar :: STM (TMVar a) #

Create a TMVar which is initially empty.

mkWeakTMVar :: TMVar a -> IO () -> IO (Weak (TMVar a)) #

Make a Weak pointer to a TMVar, using the second argument as a finalizer to run when the TMVar is garbage-collected.

Since: stm-2.4.4

isEmptyTMVar :: TMVar a -> STM Bool #

Check whether a given TMVar is empty.

data TChan a #

TChan is an abstract type representing an unbounded FIFO channel.

Instances

Instances details
Eq (TChan a) 
Instance details

Defined in Control.Concurrent.STM.TChan

Methods

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

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

writeTChan :: TChan a -> a -> STM () #

Write a value to a TChan.

unGetTChan :: TChan a -> a -> STM () #

Put a data item back onto a channel, where it will be the next item read.

tryReadTChan :: TChan a -> STM (Maybe a) #

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

Since: stm-2.3

tryPeekTChan :: TChan a -> STM (Maybe a) #

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

Since: stm-2.3

readTChan :: TChan a -> STM a #

Read the next value from the TChan.

peekTChan :: TChan a -> STM a #

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

Since: stm-2.3

newTChanIO :: IO (TChan a) #

IO version of newTChan. This is useful for creating top-level TChans using unsafePerformIO, because using atomically inside unsafePerformIO isn't possible.

newTChan :: STM (TChan a) #

Build and return a new instance of TChan

newBroadcastTChanIO :: IO (TChan a) #

IO version of newBroadcastTChan.

Since: stm-2.4

newBroadcastTChan :: STM (TChan a) #

Create a write-only TChan. More precisely, readTChan will retry even after items have been written to the channel. The only way to read a broadcast channel is to duplicate it with dupTChan.

Consider a server that broadcasts messages to clients:

serve :: TChan Message -> Client -> IO loop
serve broadcastChan client = do
    myChan <- dupTChan broadcastChan
    forever $ do
        message <- readTChan myChan
        send client message

The problem with using newTChan to create the broadcast channel is that if it is only written to and never read, items will pile up in memory. By using newBroadcastTChan to create the broadcast channel, items can be garbage collected after clients have seen them.

Since: stm-2.4

isEmptyTChan :: TChan a -> STM Bool #

Returns True if the supplied TChan is empty.

dupTChan :: TChan a -> STM (TChan a) #

Duplicate a TChan: the duplicate channel begins empty, but data written to either channel from then on will be available from both. Hence this creates a kind of broadcast channel, where data written by anyone is seen by everyone else.

cloneTChan :: TChan a -> STM (TChan a) #

Clone a TChan: similar to dupTChan, but the cloned channel starts with the same content available as the original channel.

Since: stm-2.4

data TBQueue a #

TBQueue is an abstract type representing a bounded FIFO channel.

Since: stm-2.4

Instances

Instances details
Eq (TBQueue a) 
Instance details

Defined in Control.Concurrent.STM.TBQueue

Methods

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

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

writeTBQueue :: TBQueue a -> a -> STM () #

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

unGetTBQueue :: TBQueue a -> a -> STM () #

Put a data item back onto a channel, where it will be the next item read. Blocks if the queue is full.

tryReadTBQueue :: TBQueue a -> STM (Maybe a) #

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

tryPeekTBQueue :: TBQueue a -> STM (Maybe a) #

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

readTBQueue :: TBQueue a -> STM a #

Read the next value from the TBQueue.

peekTBQueue :: TBQueue a -> STM a #

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

newTBQueueIO :: Natural -> IO (TBQueue a) #

IO version of newTBQueue. This is useful for creating top-level TBQueues using unsafePerformIO, because using atomically inside unsafePerformIO isn't possible.

newTBQueue #

Arguments

:: Natural

maximum number of elements the queue can hold

-> STM (TBQueue a) 

Builds and returns a new instance of TBQueue.

lengthTBQueue :: TBQueue a -> STM Natural #

Return the length of a TBQueue.

Since: stm-2.5.0.0

isFullTBQueue :: TBQueue a -> STM Bool #

Returns True if the supplied TBQueue is full.

Since: stm-2.4.3

isEmptyTBQueue :: TBQueue a -> STM Bool #

Returns True if the supplied TBQueue is empty.

flushTBQueue :: TBQueue a -> STM [a] #

Efficiently read the entire contents of a TBQueue into a list. This function never retries.

Since: stm-2.4.5