@@ -29,55 +29,47 @@ function __atomic(ex)
29
29
error (" @atomic macro incomplete!" )
30
30
end
31
31
32
- # arithmetic and bitwise operations
32
+ # arithmetic, bitwise, and min/max operations
33
33
34
34
const ops = Dict (
35
35
:atomic_add! => + ,
36
36
:atomic_sub! => - ,
37
37
:atomic_and! => & ,
38
38
:atomic_or! => - ,
39
39
:atomic_xor! => ⊻ ,
40
+ :atomic_min! => min,
41
+ :atomic_max! => max,
40
42
)
41
43
44
+ # Note: the type T prevents type convertion (for example, Float32 -> 64)
45
+ # can lead to errors if b is chosen to be of a different, compatible type
42
46
for (name, op) in ops
43
- @eval @inline function $name (ptr, b)
44
- Core. Intrinsics. atomic_pointermodify (ptr, $ op, b, :monotonic )
47
+ @eval @inline function $name (ptr:: Ptr{T} , b:: T ) where T
48
+ Core. Intrinsics. atomic_pointermodify (ptr:: Ptr{T} , $ op, b:: T , :monotonic )
45
49
end
46
50
end
47
51
48
- # Not sure what this one is...
49
- function atomic_cas! (ptr, b)
50
- Core. Intrinsics. atomic_pointermodify (ptr, & , b , :monotonic )
52
+ # TODO : Not sure what this one is...
53
+ function atomic_cas! (ptr:: Ptr{T} , old :: T , new :: T ) where T
54
+ Core. Intrinsics. atomic_pointerswap (ptr:: Ptr{T} , x :: T , :monotonic )
51
55
end
52
56
53
- # TODO
54
- function atomic_dec! (ptr, b)
55
- Core. Intrinsics. atomic_pointermodify (ptr, & , b , :monotonic )
57
+ # TODO : Not sure what this one is...
58
+ function atomic_dec! (ptr:: Ptr{T} , b:: T ) where T
59
+ Core. Intrinsics. atomic_pointermodify (ptr, - , 1 , :monotonic )
56
60
end
57
61
58
- # TODO
59
- function atomic_inc! (ptr, b)
60
- Core. Intrinsics. atomic_pointermodify (ptr, & , b , :monotonic )
62
+ # TODO : Not sure what this one is...
63
+ function atomic_inc! (ptr:: Ptr{T} , b:: T ) where T
64
+ Core. Intrinsics. atomic_pointermodify (ptr, + , 1 , :monotonic )
61
65
end
62
66
63
- # TODO
64
- function atomic_max! (ptr, b)
65
- Core. Intrinsics. atomic_pointermodify (ptr, & , b, :monotonic )
67
+ function atomic_xchg! (ptr:: Ptr{T} , b:: T ) where T
68
+ Core. Intrinsics. atomic_pointerswap (ptr:: Ptr{T} , x:: T , :monotonic )
66
69
end
67
70
68
- # TODO
69
- function atomic_min! (ptr, b)
70
- Core. Intrinsics. atomic_pointermodify (ptr, & , b, :monotonic )
71
- end
72
-
73
- # TODO
74
- function atomic_op! (ptr, b)
75
- Core. Intrinsics. atomic_pointermodify (ptr, & , b, :monotonic )
76
- end
77
-
78
- # TODO
79
- function atomic_xchg! (ptr, b)
80
- Core. Intrinsics. atomic_pointermodify (ptr, & , b, :monotonic )
71
+ function atomic_op! (ptr:: Ptr{T} , op, b:: T ) where T
72
+ Core. Intrinsics. atomic_pointermodify (ptr:: Ptr{T} , op, b:: T , :monotonic )
81
73
end
82
74
83
75
# ##
0 commit comments