Skip to content

Commit 98ba5a0

Browse files
Int64# was added in GHC 9.4.x
1 parent e5439d2 commit 98ba5a0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Data/Atomic.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@ 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+
#else
50+
int64ToInt :: Int# -> Int#
51+
int64ToInt i = i
52+
#endif
53+
4654
-- | A mutable, atomic integer.
4755
data Atomic = C (MutableByteArray# RealWorld)
4856

4957
-- | Create a new, zero initialized, atomic.
5058
new :: Int64 -> IO Atomic
5159
new (I64# n64) = IO $ \s ->
5260
case newByteArray# SIZEOF_HSINT# s of { (# s1, mba #) ->
53-
case atomicWriteIntArray# mba 0# (int64ToInt# n64) s1 of { s2 ->
61+
case atomicWriteIntArray# mba 0# (int64ToInt n64) s1 of { s2 ->
5462
(# s2, C mba #) }}
5563

5664
read :: Atomic -> IO Int64
@@ -61,19 +69,19 @@ read (C mba) = IO $ \s ->
6169
-- | Set the atomic to the given value.
6270
write :: Atomic -> Int64 -> IO ()
6371
write (C mba) (I64# n64) = IO $ \s ->
64-
case atomicWriteIntArray# mba 0# (int64ToInt# n64) s of { s1 ->
72+
case atomicWriteIntArray# mba 0# (int64ToInt n64) s of { s1 ->
6573
(# s1, () #) }
6674

6775
-- | Increase the atomic by the given amount.
6876
add :: Atomic -> Int64 -> IO ()
6977
add (C mba) (I64# n64) = IO $ \s ->
70-
case fetchAddIntArray# mba 0# (int64ToInt# n64) s of { (# s1, _ #) ->
78+
case fetchAddIntArray# mba 0# (int64ToInt n64) s of { (# s1, _ #) ->
7179
(# s1, () #) }
7280

7381
-- | Decrease the atomic by the given amount.
7482
subtract :: Atomic -> Int64 -> IO ()
7583
subtract (C mba) (I64# n64) = IO $ \s ->
76-
case fetchSubIntArray# mba 0# (int64ToInt# n64) s of { (# s1, _ #) ->
84+
case fetchSubIntArray# mba 0# (int64ToInt n64) s of { (# s1, _ #) ->
7785
(# s1, () #) }
7886

7987
#else

0 commit comments

Comments
 (0)