{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleContexts #-}
#if __GLASGOW_HASKELL__ >= 704
{-# LANGUAGE Safe #-}
#endif
module Data.IORef.Lifted
( IORef
, newIORef
, readIORef
, writeIORef
, modifyIORef
#if MIN_VERSION_base(4,6,0)
, modifyIORef'
#endif
, atomicModifyIORef
#if MIN_VERSION_base(4,6,0)
, atomicModifyIORef'
, atomicWriteIORef
#endif
, mkWeakIORef
) where
import Data.IORef ( IORef )
import qualified Data.IORef as R
import System.IO ( IO )
import System.Mem.Weak ( Weak )
import Prelude ( (.) )
import Control.Monad.Base ( MonadBase, liftBase )
import Control.Monad.Trans.Control ( MonadBaseControl, liftBaseDiscard )
#include "inlinable.h"
newIORef :: MonadBase IO m => a -> m (IORef a)
newIORef :: forall (m :: * -> *) a. MonadBase IO m => a -> m (IORef a)
newIORef = IO (IORef a) -> m (IORef a)
forall α. IO α -> m α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO (IORef a) -> m (IORef a))
-> (a -> IO (IORef a)) -> a -> m (IORef a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> IO (IORef a)
forall a. a -> IO (IORef a)
R.newIORef
{-# INLINABLE newIORef #-}
readIORef :: MonadBase IO m => IORef a -> m a
readIORef :: forall (m :: * -> *) a. MonadBase IO m => IORef a -> m a
readIORef = IO a -> m a
forall α. IO α -> m α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO a -> m a) -> (IORef a -> IO a) -> IORef a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef a -> IO a
forall a. IORef a -> IO a
R.readIORef
{-# INLINABLE readIORef #-}
writeIORef :: MonadBase IO m => IORef a -> a -> m ()
writeIORef :: forall (m :: * -> *) a. MonadBase IO m => IORef a -> a -> m ()
writeIORef IORef a
r = IO () -> m ()
forall α. IO α -> m α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO () -> m ()) -> (a -> IO ()) -> a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef a -> a -> IO ()
forall a. IORef a -> a -> IO ()
R.writeIORef IORef a
r
{-# INLINABLE writeIORef #-}
modifyIORef :: MonadBase IO m => IORef a -> (a -> a) -> m ()
modifyIORef :: forall (m :: * -> *) a.
MonadBase IO m =>
IORef a -> (a -> a) -> m ()
modifyIORef IORef a
r = IO () -> m ()
forall α. IO α -> m α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO () -> m ()) -> ((a -> a) -> IO ()) -> (a -> a) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef a -> (a -> a) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
R.modifyIORef IORef a
r
{-# INLINABLE modifyIORef #-}
atomicModifyIORef :: MonadBase IO m => IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef :: forall (m :: * -> *) a b.
MonadBase IO m =>
IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef IORef a
r = IO b -> m b
forall α. IO α -> m α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO b -> m b) -> ((a -> (a, b)) -> IO b) -> (a -> (a, b)) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef a -> (a -> (a, b)) -> IO b
forall a b. IORef a -> (a -> (a, b)) -> IO b
R.atomicModifyIORef IORef a
r
{-# INLINABLE atomicModifyIORef #-}
#if MIN_VERSION_base(4,6,0)
modifyIORef' :: MonadBase IO m => IORef a -> (a -> a) -> m ()
modifyIORef' :: forall (m :: * -> *) a.
MonadBase IO m =>
IORef a -> (a -> a) -> m ()
modifyIORef' IORef a
r = IO () -> m ()
forall α. IO α -> m α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO () -> m ()) -> ((a -> a) -> IO ()) -> (a -> a) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef a -> (a -> a) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
R.modifyIORef' IORef a
r
{-# INLINABLE modifyIORef' #-}
atomicModifyIORef' :: MonadBase IO m => IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef' :: forall (m :: * -> *) a b.
MonadBase IO m =>
IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef' IORef a
r = IO b -> m b
forall α. IO α -> m α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO b -> m b) -> ((a -> (a, b)) -> IO b) -> (a -> (a, b)) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef a -> (a -> (a, b)) -> IO b
forall a b. IORef a -> (a -> (a, b)) -> IO b
R.atomicModifyIORef' IORef a
r
{-# INLINABLE atomicModifyIORef' #-}
atomicWriteIORef :: MonadBase IO m => IORef a -> a -> m ()
atomicWriteIORef :: forall (m :: * -> *) a. MonadBase IO m => IORef a -> a -> m ()
atomicWriteIORef IORef a
r = IO () -> m ()
forall α. IO α -> m α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase (IO () -> m ()) -> (a -> IO ()) -> a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef a -> a -> IO ()
forall a. IORef a -> a -> IO ()
R.atomicWriteIORef IORef a
r
#endif
mkWeakIORef :: MonadBaseControl IO m => IORef a -> m () -> m (Weak (IORef a))
mkWeakIORef :: forall (m :: * -> *) a.
MonadBaseControl IO m =>
IORef a -> m () -> m (Weak (IORef a))
mkWeakIORef = (IO () -> IO (Weak (IORef a))) -> m () -> m (Weak (IORef a))
forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(b () -> b a) -> m () -> m a
liftBaseDiscard ((IO () -> IO (Weak (IORef a))) -> m () -> m (Weak (IORef a)))
-> (IORef a -> IO () -> IO (Weak (IORef a)))
-> IORef a
-> m ()
-> m (Weak (IORef a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef a -> IO () -> IO (Weak (IORef a))
forall a. IORef a -> IO () -> IO (Weak (IORef a))
R.mkWeakIORef
{-# INLINABLE mkWeakIORef #-}