{-# OPTIONS_GHC -Wunused-imports #-}

-- | Utilities for Data.IORef.

module Agda.Utils.IORef
  ( module Data.IORef
  , module Agda.Utils.IORef
  ) where

import Data.IORef

-- | Read 'IORef', modify it strictly, and return old value.
readModifyIORef' :: IORef a -> (a -> a) -> IO a
readModifyIORef' :: forall a. IORef a -> (a -> a) -> IO a
readModifyIORef' IORef a
ref a -> a
f = do
    x <- IORef a -> IO a
forall a. IORef a -> IO a
readIORef IORef a
ref
    writeIORef ref $! f x
    return x