@@ -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.
4761data Atomic = C (MutableByteArray # RealWorld )
4862
4963-- | Create a new, zero initialized, atomic.
5064new :: Int64 -> IO Atomic
5165new (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
5670read :: Atomic -> IO Int64
5771read (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.
6276write :: Atomic -> Int64 -> IO ()
6377write (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.
6882add :: Atomic -> Int64 -> IO ()
6983add (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.
7488subtract :: Atomic -> Int64 -> IO ()
7589subtract (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