@@ -10,13 +10,18 @@ function check_default_ordering(T::Type)
10
10
xs = T[rand (T), rand (T)]
11
11
x1 = rand (T)
12
12
x2 = rand (T)
13
+ check_default_ordering (xs, x1, x2)
14
+ end
15
+
16
+ function check_default_ordering (xs:: AbstractArray{T} , x1:: T , x2:: T ) where T
13
17
@debug " xs=$(repr (xs)) x1=$(repr (x1)) x2=$(repr (x2)) "
14
18
15
19
ptr = llvmptr (xs, 1 )
16
20
GC. @preserve xs begin
17
21
@test UnsafeAtomics. load (ptr) === xs[1 ]
18
22
UnsafeAtomics. store! (ptr, x1)
19
23
@test xs[1 ] === x1
24
+ sizeof (T) == 0 && return # CAS hangs on zero sized data...
20
25
desired = (old = x1, success = true )
21
26
@test UnsafeAtomics. cas! (ptr, x1, x2) === (old = x1, success = true )
22
27
@test xs[1 ] === x2
@@ -37,6 +42,10 @@ function test_explicit_ordering(T::Type = UInt)
37
42
xs = T[rand (T), rand (T)]
38
43
x1 = rand (T)
39
44
x2 = rand (T)
45
+ test_explicit_ordering (xs, x1, x2)
46
+ end
47
+
48
+ function test_explicit_ordering (xs:: AbstractArray{T} , x1:: T , x2:: T ) where T
40
49
@debug " xs=$(repr (xs)) x1=$(repr (x1)) x2=$(repr (x2)) "
41
50
42
51
ptr = llvmptr (xs, 1 )
@@ -45,6 +54,7 @@ function test_explicit_ordering(T::Type = UInt)
45
54
@test UnsafeAtomics. load (ptr, acquire) === xs[1 ]
46
55
UnsafeAtomics. store! (ptr, x1, release)
47
56
@test xs[1 ] === x1
57
+ sizeof (T) == 0 && return # CAS hangs on zero sized data...
48
58
desired = (old = x1, success = true )
49
59
@test UnsafeAtomics. cas! (ptr, x1, x2, acq_rel, acquire) === desired
50
60
@test xs[1 ] === x2
@@ -74,9 +84,16 @@ function test_explicit_ordering(T::Type = UInt)
74
84
end
75
85
end
76
86
87
+
77
88
@testset " UnsafeAtomicsLLVM" begin
78
89
@testset for T in inttypes
79
90
check_default_ordering (T)
80
91
test_explicit_ordering (T)
81
92
end
93
+
94
+ @testset " Zero-sized types" begin
95
+ @test sizeof (Nothing) == 0
96
+ check_default_ordering ([nothing , nothing ], nothing , nothing )
97
+ test_explicit_ordering ([nothing , nothing ], nothing , nothing )
98
+ end
82
99
end
0 commit comments