@@ -6,8 +6,7 @@ export @atomic, atomic_add!, atomic_sub!, atomic_and!, atomic_or!, atomic_xor!,
6
6
atomic_min!, atomic_max!, atomic_inc!, atomic_dec!, atomic_xchg!,
7
7
atomic_op!, atomic_cas!
8
8
9
- # helper functions for inc and dec
10
-
9
+ # helper functions for inc(rement) and dec(rement)
11
10
function dec (a:: T ,b:: T ) where T
12
11
((a == 0 ) | (a > b)) ? b : (a- T (1 ))
13
12
end
@@ -43,8 +42,7 @@ function __atomic(ex)
43
42
error (" @atomic macro incomplete!" )
44
43
end
45
44
46
- # arithmetic, bitwise, and min/max operations
47
-
45
+ # arithmetic, bitwise, min/max, and inc/dec operations
48
46
const ops = Dict (
49
47
:atomic_add! => + ,
50
48
:atomic_sub! => - ,
@@ -53,6 +51,8 @@ const ops = Dict(
53
51
:atomic_xor! => ⊻ ,
54
52
:atomic_min! => min,
55
53
:atomic_max! => max,
54
+ :atomic_inc! => inc,
55
+ :atomic_dec! => dec,
56
56
)
57
57
58
58
# Note: the type T prevents type convertion (for example, Float32 -> 64)
@@ -67,16 +67,6 @@ function atomic_cas!(ptr::Ptr{T}, old::T, new::T) where T
67
67
Core. Intrinsics. atomic_pointerreplace (ptr:: Ptr{T} , old, new, :release_acquire , :monotonic )
68
68
end
69
69
70
- # Implementation of: (((old == 0) | (old > b)) ? b : (old-1)), returns old
71
- function atomic_dec! (ptr:: Ptr{T} , b:: T ) where T
72
- Core. Intrinsics. atomic_pointermodify (ptr:: Ptr{T} , dec, b:: T , :monotonic )
73
- end
74
-
75
- # implementation of: ((old >= b) ? 0 : (old+1)), returns old
76
- function atomic_inc! (ptr:: Ptr{T} , b:: T ) where T
77
- Core. Intrinsics. atomic_pointermodify (ptr:: Ptr{T} , inc, b:: T , :monotonic )
78
- end
79
-
80
70
function atomic_xchg! (ptr:: Ptr{T} , b:: T ) where T
81
71
Core. Intrinsics. atomic_pointerswap (ptr:: Ptr{T} , x:: T , :monotonic )
82
72
end
0 commit comments