@@ -43,14 +43,20 @@ 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 = int64ToInt#
48
+ #else
49
+ int64ToInt i = i
50
+ #endif
51
+
46
52
-- | A mutable, atomic integer.
47
53
data Atomic = C (MutableByteArray # RealWorld )
48
54
49
55
-- | Create a new, zero initialized, atomic.
50
56
new :: Int64 -> IO Atomic
51
57
new (I64 # n64) = IO $ \ s ->
52
58
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 ->
54
60
(# s2, C mba # ) }}
55
61
56
62
read :: Atomic -> IO Int64
@@ -61,19 +67,19 @@ read (C mba) = IO $ \s ->
61
67
-- | Set the atomic to the given value.
62
68
write :: Atomic -> Int64 -> IO ()
63
69
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 ->
65
71
(# s1, () # ) }
66
72
67
73
-- | Increase the atomic by the given amount.
68
74
add :: Atomic -> Int64 -> IO ()
69
75
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, _ # ) ->
71
77
(# s1, () # ) }
72
78
73
79
-- | Decrease the atomic by the given amount.
74
80
subtract :: Atomic -> Int64 -> IO ()
75
81
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, _ # ) ->
77
83
(# s1, () # ) }
78
84
79
85
#else
0 commit comments