Skip to content

Commit 23619c9

Browse files
Int64# was added in GHC 9.4.x
1 parent e5439d2 commit 23619c9

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Data/Atomic.hs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,51 @@ import Data.IORef
4343
-- 64-bit machine, Int ~ Int64, do it the fast way:
4444
#if SIZEOF_HSINT == 8
4545

46+
#if MIN_VERSION_base(4,17,0)
47+
int64ToInt :: Int64# -> Int#
48+
int64ToInt = int64ToInt#
49+
50+
intToInt64 :: Int# -> Int64#
51+
intToInt64 = intToInt64#
52+
#else
53+
int64ToInt :: Int# -> Int#
54+
int64ToInt i = i
55+
56+
intToInt64 :: Int# -> Int#
57+
intToInt64 i = i
58+
#endif
59+
4660
-- | A mutable, atomic integer.
4761
data Atomic = C (MutableByteArray# RealWorld)
4862

4963
-- | Create a new, zero initialized, atomic.
5064
new :: Int64 -> IO Atomic
5165
new (I64# n64) = IO $ \s ->
5266
case newByteArray# SIZEOF_HSINT# s of { (# s1, mba #) ->
53-
case atomicWriteIntArray# mba 0# (int64ToInt# n64) s1 of { s2 ->
67+
case atomicWriteIntArray# mba 0# (int64ToInt n64) s1 of { s2 ->
5468
(# s2, C mba #) }}
5569

5670
read :: Atomic -> IO Int64
5771
read (C mba) = IO $ \s ->
5872
case atomicReadIntArray# mba 0# s of { (# s1, n #) ->
59-
(# s1, I64# (intToInt64# n) #)}
73+
(# s1, I64# (intToInt64 n) #)}
6074

6175
-- | Set the atomic to the given value.
6276
write :: Atomic -> Int64 -> IO ()
6377
write (C mba) (I64# n64) = IO $ \s ->
64-
case atomicWriteIntArray# mba 0# (int64ToInt# n64) s of { s1 ->
78+
case atomicWriteIntArray# mba 0# (int64ToInt n64) s of { s1 ->
6579
(# s1, () #) }
6680

6781
-- | Increase the atomic by the given amount.
6882
add :: Atomic -> Int64 -> IO ()
6983
add (C mba) (I64# n64) = IO $ \s ->
70-
case fetchAddIntArray# mba 0# (int64ToInt# n64) s of { (# s1, _ #) ->
84+
case fetchAddIntArray# mba 0# (int64ToInt n64) s of { (# s1, _ #) ->
7185
(# s1, () #) }
7286

7387
-- | Decrease the atomic by the given amount.
7488
subtract :: Atomic -> Int64 -> IO ()
7589
subtract (C mba) (I64# n64) = IO $ \s ->
76-
case fetchSubIntArray# mba 0# (int64ToInt# n64) s of { (# s1, _ #) ->
90+
case fetchSubIntArray# mba 0# (int64ToInt n64) s of { (# s1, _ #) ->
7791
(# s1, () #) }
7892

7993
#else

0 commit comments

Comments
 (0)