From 41b183d6eae567f7184a8be8fa241f82ded5cbf2 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Wed, 13 Jan 2021 11:03:46 -0500 Subject: FastMutInt: Introduce atomicFetchAddFastMutInt This will be needed by FastString. --- compiler/GHC/Data/FastMutInt.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/compiler/GHC/Data/FastMutInt.hs b/compiler/GHC/Data/FastMutInt.hs index bc4c413bdc..e2e3a50601 100644 --- a/compiler/GHC/Data/FastMutInt.hs +++ b/compiler/GHC/Data/FastMutInt.hs @@ -9,7 +9,8 @@ module GHC.Data.FastMutInt( FastMutInt, newFastMutInt, - readFastMutInt, writeFastMutInt + readFastMutInt, writeFastMutInt, + atomicFetchAddFastMut ) where import GHC.Prelude @@ -27,15 +28,20 @@ newFastMutInt n = do where !(I# size) = finiteBitSize (0 :: Int) `unsafeShiftR` 3 create = IO $ \s -> - case newByteArray# size s of { (# s, arr #) -> - (# s, FastMutInt arr #) } + case newByteArray# size s of + (# s, arr #) -> (# s, FastMutInt arr #) readFastMutInt :: FastMutInt -> IO Int readFastMutInt (FastMutInt arr) = IO $ \s -> - case readIntArray# arr 0# s of { (# s, i #) -> - (# s, I# i #) } + case readIntArray# arr 0# s of + (# s, i #) -> (# s, I# i #) writeFastMutInt :: FastMutInt -> Int -> IO () writeFastMutInt (FastMutInt arr) (I# i) = IO $ \s -> - case writeIntArray# arr 0# i s of { s -> - (# s, () #) } + case writeIntArray# arr 0# i s of + s -> (# s, () #) + +atomicFetchAddFastMut :: FastMutInt -> Int -> IO Int +atomicFetchAddFastMut (FastMutInt arr) (I# i) = IO $ \s -> + case fetchAddIntArray# arr 0# i s of + (# s, n #) -> (# s, I# n #) -- cgit v1.2.1