Skip to content

Commit a8cd12d

Browse files
committed
adding docstrings
1 parent 727850c commit a8cd12d

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

src/atomics.jl

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,46 @@ for (name, op) in ops
6363
end
6464
end
6565

66+
"""
67+
atomic_cas!(ptr::Ptr{T}, cmp::T, val::T)
68+
69+
This is an atomic Compare And Swap (CAS).
70+
It reads the value `old` located at address `ptr` and compare with `cmp`.
71+
If `old` equals `cmp`, it stores `val` at the same address.
72+
Otherwise, doesn't change the value `old`.
73+
These operations are performed in one atomic transaction.
74+
The function returns `old`.
75+
76+
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
77+
Additionally, on GPU hardware with compute capability 7.0+, values of type UInt1
78+
6 are supported.
79+
"""
6680
function atomic_cas!(ptr::Ptr{T}, old::T, new::T) where T
6781
Core.Intrinsics.atomic_pointerreplace(ptr, old, new, :acquire_release, :monotonic)
6882
end
6983

84+
"""
85+
atomic_xchg!(ptr::Ptr{T}, val::T)
86+
87+
This is an atomic exchange.
88+
It reads the value `old` located at address `ptr` and stores `val` at the same address.
89+
These operations are performed in one atomic transaction. The function returns `old`.
90+
91+
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
92+
"""
7093
function atomic_xchg!(ptr::Ptr{T}, b::T) where T
7194
Core.Intrinsics.atomic_pointerswap(ptr::Ptr{T}, b::T, :monotonic)
7295
end
7396

97+
"""
98+
atomic_op!(ptr::Ptr{T}, val::T)
99+
100+
This is an arbitrary atomic operation.
101+
It reads the value `old` located at address `ptr` and uses `val` in the operation `op` (defined elsewhere)
102+
These operations are performed in one atomic transaction. The function returns `old`.
103+
104+
This function is somewhat experimental.
105+
"""
74106
function atomic_op!(ptr::Ptr{T}, op, b::T) where T
75107
Core.Intrinsics.atomic_pointermodify(ptr::Ptr{T}, op, b::T, :monotonic)
76108
end
@@ -83,3 +115,113 @@ end
83115
# println(ex)
84116
#end
85117

118+
# Other Documentation
119+
120+
"""
121+
atomic_add!(ptr::LLVMPtr{T}, val::T)
122+
123+
This is an atomic addition.
124+
It reads the value `old` located at address `ptr`, computes `old + val`, and stores the result back to memory at the same address.
125+
These operations are performed in one atomic transaction.
126+
The function returns `old`.
127+
128+
This operation is supported for values of type Int32, Int64, UInt32, UInt64, and Float32.
129+
Additionally, on GPU hardware with compute capability 6.0+, values of type Float64 are supported.
130+
"""
131+
atomic_add!
132+
133+
"""
134+
atomic_sub!(ptr::LLVMPtr{T}, val::T)
135+
136+
This is an atomic subtraction.
137+
It reads the value `old` located at address `ptr`, computes `old - val`, and stores the result back to memory at the same address.
138+
These operations are performed in one atomic transaction.
139+
The function returns `old`.
140+
141+
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
142+
"""
143+
atomic_sub!
144+
145+
"""
146+
atomic_and!(ptr::LLVMPtr{T}, val::T)
147+
148+
This is an atomic and.
149+
It reads the value `old` located at address `ptr`, computes `old & val`, and stores the result back to memory at the same address.
150+
These operations are performed in one atomic transaction.
151+
The function returns `old`.
152+
153+
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
154+
"""
155+
atomic_and!
156+
157+
"""
158+
atomic_or!(ptr::LLVMPtr{T}, val::T)
159+
160+
This is an atomic or.
161+
It reads the value `old` located at address `ptr`, computes `old | val`, and stores the result back to memory at the same address.
162+
These operations are performed in one atomic transaction.
163+
The function returns `old`.
164+
165+
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
166+
"""
167+
atomic_or!
168+
169+
"""
170+
atomic_xor!(ptr::LLVMPtr{T}, val::T)
171+
172+
This is an atomic xor.
173+
It reads the value `old` located at address `ptr`, computes `old ⊻ val`, and stores the result back to memory at the same address.
174+
These operations are performed in one atomic transaction.
175+
The function returns `old`.
176+
177+
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
178+
"""
179+
atomic_xor!
180+
181+
"""
182+
atomic_min!(ptr::LLVMPtr{T}, val::T)
183+
184+
This is an atomic min.
185+
It reads the value `old` located at address `ptr`, computes `min(old, val)`, and st ores the result back to memory at the same address.
186+
These operations are performed in one atomic transaction.
187+
The function returns `old`.
188+
189+
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
190+
"""
191+
atomic_min!
192+
193+
"""
194+
atomic_max!(ptr::LLVMPtr{T}, val::T)
195+
196+
This is an atomic max.
197+
It reads the value `old` located at address `ptr`, computes `max(old, val)`, and st ores the result back to memory at the same address.
198+
These operations are performed in one atomic transaction.
199+
The function returns `old`.
200+
201+
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
202+
"""
203+
atomic_max!
204+
205+
"""
206+
atomic_inc!(ptr::LLVMPtr{T}, val::T)
207+
208+
This is an atomic increment function that counts up to a certain number before starting again at 0.
209+
It reads the value `old` located at address `ptr`, computes `((old >= val) ? 0 : (o ld+1))`, and stores the result back to memory at the same address.
210+
These three operations are performed in one atomic transaction.
211+
The function returns `old`.
212+
213+
This operation is only supported for values of type Int32.
214+
"""
215+
atomic_inc!
216+
217+
"""
218+
atomic_dec!(ptr::LLVMPtr{T}, val::T)
219+
220+
This is an atomic decrement function that counts down to 0 from a defined value `val`.
221+
It reads the value `old` located at address `ptr`, computes `(((old == 0) | (old > val)) ? val : (old-1))`, and stores the result back to memory at the same address.
222+
These three operations are performed in one atomic transaction.
223+
The function returns `old`.
224+
225+
This operation is only supported for values of type Int32.
226+
"""
227+
atomic_dec!

0 commit comments

Comments
 (0)