@@ -43,14 +43,22 @@ import Data.IORef
43
43
-- 64-bit machine, Int ~ Int64, do it the fast way:
44
44
#if SIZEOF_HSINT == 8
45
45
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
+
46
54
-- | A mutable, atomic integer.
47
55
data Atomic = C (MutableByteArray # RealWorld )
48
56
49
57
-- | Create a new, zero initialized, atomic.
50
58
new :: Int64 -> IO Atomic
51
59
new (I64 # n64) = IO $ \ s ->
52
60
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 ->
54
62
(# s2, C mba # ) }}
55
63
56
64
read :: Atomic -> IO Int64
@@ -61,19 +69,19 @@ read (C mba) = IO $ \s ->
61
69
-- | Set the atomic to the given value.
62
70
write :: Atomic -> Int64 -> IO ()
63
71
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 ->
65
73
(# s1, () # ) }
66
74
67
75
-- | Increase the atomic by the given amount.
68
76
add :: Atomic -> Int64 -> IO ()
69
77
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, _ # ) ->
71
79
(# s1, () # ) }
72
80
73
81
-- | Decrease the atomic by the given amount.
74
82
subtract :: Atomic -> Int64 -> IO ()
75
83
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, _ # ) ->
77
85
(# s1, () # ) }
78
86
79
87
#else
0 commit comments