@@ -49,19 +49,26 @@ for (name, op) in ops
49
49
end
50
50
end
51
51
52
- # TODO : Not sure what this one is...
53
52
function atomic_cas! (ptr:: Ptr{T} , old:: T , new:: T ) where T
54
53
Core. Intrinsics. atomic_pointerreplace (ptr:: Ptr{T} , old, new, :release_acquire , :monotonic )
55
54
end
56
55
57
- # TODO : Not sure what this one is...
56
+ # Implementation of: (((old == 0) | (old > b)) ? b : (old-1)), returns old
58
57
function atomic_dec! (ptr:: Ptr{T} , b:: T ) where T
59
- Core. Intrinsics. atomic_pointermodify (ptr, - , 1 , :monotonic )
58
+ if (unsafe_load (ptr) == 0 | unsafe_load (ptr) > b)
59
+ Core. Intrinsics. atomic_pointerswap (ptr, b, :monotonic )
60
+ else
61
+ Core. Intrinsics. atomic_pointermodify (ptr, - , 1 , :monotonic )
62
+ end
60
63
end
61
64
62
- # TODO : Not sure what this one is...
65
+ # implementation of: ((old >= b) ? 0 : (old+1)), returns old
63
66
function atomic_inc! (ptr:: Ptr{T} , b:: T ) where T
64
- Core. Intrinsics. atomic_pointermodify (ptr, + , 1 , :monotonic )
67
+ if unsafe_load (ptr) >= b
68
+ Core. Intrinsics. atomic_pointerswap (ptr, 0 , :monotonic )
69
+ else
70
+ Core. Intrinsics. atomic_pointermodify (ptr, + , 1 , :monotonic )
71
+ end
65
72
end
66
73
67
74
function atomic_xchg! (ptr:: Ptr{T} , b:: T ) where T
0 commit comments