Skip to content

Commit 4a575bc

Browse files
Int64# was added in GHC 9.4.x
1 parent e5439d2 commit 4a575bc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Data/Atomic.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,20 @@ 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 = int64ToInt#
48+
#else
49+
int64ToInt i = i
50+
#endif
51+
4652
-- | A mutable, atomic integer.
4753
data Atomic = C (MutableByteArray# RealWorld)
4854

4955
-- | Create a new, zero initialized, atomic.
5056
new :: Int64 -> IO Atomic
5157
new (I64# n64) = IO $ \s ->
5258
case newByteArray# SIZEOF_HSINT# s of { (# s1, mba #) ->
53-
case atomicWriteIntArray# mba 0# (int64ToInt# n64) s1 of { s2 ->
59+
case atomicWriteIntArray# mba 0# (int64ToInt n64) s1 of { s2 ->
5460
(# s2, C mba #) }}
5561

5662
read :: Atomic -> IO Int64
@@ -61,19 +67,19 @@ read (C mba) = IO $ \s ->
6167
-- | Set the atomic to the given value.
6268
write :: Atomic -> Int64 -> IO ()
6369
write (C mba) (I64# n64) = IO $ \s ->
64-
case atomicWriteIntArray# mba 0# (int64ToInt# n64) s of { s1 ->
70+
case atomicWriteIntArray# mba 0# (int64ToInt n64) s of { s1 ->
6571
(# s1, () #) }
6672

6773
-- | Increase the atomic by the given amount.
6874
add :: Atomic -> Int64 -> IO ()
6975
add (C mba) (I64# n64) = IO $ \s ->
70-
case fetchAddIntArray# mba 0# (int64ToInt# n64) s of { (# s1, _ #) ->
76+
case fetchAddIntArray# mba 0# (int64ToInt n64) s of { (# s1, _ #) ->
7177
(# s1, () #) }
7278

7379
-- | Decrease the atomic by the given amount.
7480
subtract :: Atomic -> Int64 -> IO ()
7581
subtract (C mba) (I64# n64) = IO $ \s ->
76-
case fetchSubIntArray# mba 0# (int64ToInt# n64) s of { (# s1, _ #) ->
82+
case fetchSubIntArray# mba 0# (int64ToInt n64) s of { (# s1, _ #) ->
7783
(# s1, () #) }
7884

7985
#else

0 commit comments

Comments
 (0)