@@ -49,19 +49,26 @@ for (name, op) in ops
4949 end
5050end
5151
52- # TODO : Not sure what this one is...
5352function atomic_cas! (ptr:: Ptr{T} , old:: T , new:: T ) where T
5453 Core. Intrinsics. atomic_pointerreplace (ptr:: Ptr{T} , old, new, :release_acquire , :monotonic )
5554end
5655
57- # TODO : Not sure what this one is...
56+ # Implementation of: (((old == 0) | (old > b)) ? b : (old-1)), returns old
5857function 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
6063end
6164
62- # TODO : Not sure what this one is...
65+ # implementation of: ((old >= b) ? 0 : (old+1)), returns old
6366function 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
6572end
6673
6774function atomic_xchg! (ptr:: Ptr{T} , b:: T ) where T
0 commit comments