summaryrefslogtreecommitdiff
path: root/compiler/GHC/Data
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-01-13 11:03:46 -0500
committerBen Gamari <ben@smart-cactus.org>2021-03-10 13:20:55 -0500
commit41b183d6eae567f7184a8be8fa241f82ded5cbf2 (patch)
tree47b3b42b0d53aaca83c9622bca69917040ea9777 /compiler/GHC/Data
parente6c9b1e6ddd82fab47207ff17efeabdf0deb6fc7 (diff)
downloadhaskell-41b183d6eae567f7184a8be8fa241f82ded5cbf2.tar.gz
FastMutInt: Introduce atomicFetchAddFastMutInt
This will be needed by FastString.
Diffstat (limited to 'compiler/GHC/Data')
-rw-r--r--compiler/GHC/Data/FastMutInt.hs20
1 files 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 #)