Skip to content

Commit e28f9b4

Browse files
committed
adding inc and dec to op set
1 parent e664758 commit e28f9b4

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/atomics.jl

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ export @atomic, atomic_add!, atomic_sub!, atomic_and!, atomic_or!, atomic_xor!,
66
atomic_min!, atomic_max!, atomic_inc!, atomic_dec!, atomic_xchg!,
77
atomic_op!, atomic_cas!
88

9-
# helper functions for inc and dec
10-
9+
# helper functions for inc(rement) and dec(rement)
1110
function dec(a::T,b::T) where T
1211
((a == 0) | (a > b)) ? b : (a-T(1))
1312
end
@@ -43,8 +42,7 @@ function __atomic(ex)
4342
error("@atomic macro incomplete!")
4443
end
4544

46-
# arithmetic, bitwise, and min/max operations
47-
45+
# arithmetic, bitwise, min/max, and inc/dec operations
4846
const ops = Dict(
4947
:atomic_add! => +,
5048
:atomic_sub! => -,
@@ -53,6 +51,8 @@ const ops = Dict(
5351
:atomic_xor! => ,
5452
:atomic_min! => min,
5553
:atomic_max! => max,
54+
:atomic_inc! => inc,
55+
:atomic_dec! => dec,
5656
)
5757

5858
# 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
6767
Core.Intrinsics.atomic_pointerreplace(ptr::Ptr{T}, old, new, :release_acquire, :monotonic)
6868
end
6969

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-
8070
function atomic_xchg!(ptr::Ptr{T}, b::T) where T
8171
Core.Intrinsics.atomic_pointerswap(ptr::Ptr{T}, x::T, :monotonic)
8272
end

0 commit comments

Comments
 (0)