blob: 07713c217d1192b8fcd08c9f1d36356f4ed79b61 [file] [log] [blame]
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -07001#
2# Copyright (C) 2015 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17header:
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070018summary: Atomic Update Functions
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070019description:
20 To update values shared between multiple threads, use the functions below.
21 They ensure that the values are atomically updated, i.e. that the memory
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070022 reads, the updates, and the memory writes are done in the right order.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070023
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070024 These functions are slower than their non-atomic equivalents, so use
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070025 them only when synchronization is needed.
26
27 Note that in RenderScript, your code is likely to be running in separate
28 threads even though you did not explicitely create them. The RenderScript
29 runtime will very often split the execution of one kernel across multiple
30 threads. Updating globals should be done with atomic functions. If possible,
31 modify your algorithm to avoid them altogether.
32end:
33
34function: rsAtomicAdd
35version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070036ret: int32_t, "Value of *addr prior to the operation."
37arg: volatile int32_t* addr, "Address of the value to modify."
38arg: int32_t value, "Amount to add."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070039summary: Thread-safe addition
40description:
41 Atomicly adds a value to the value at addr, i.e. <code>*addr += value</code>.
42test: none
43end:
44
45function: rsAtomicAdd
46version: 20
47ret: int32_t
48arg: volatile uint32_t* addr
49arg: uint32_t value
50test: none
51end:
52
53function: rsAtomicAnd
54version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070055ret: int32_t, "Value of *addr prior to the operation."
56arg: volatile int32_t* addr, "Address of the value to modify."
57arg: int32_t value, "Value to and with."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070058summary: Thread-safe bitwise and
59description:
60 Atomicly performs a bitwise and of two values, storing the result back at addr,
Jean-Luc Brouillet6386ceb2015-04-28 15:06:30 -070061 i.e. <code>*addr &amp;= value</code>.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070062test: none
63end:
64
65function: rsAtomicAnd
66version: 20
67ret: int32_t
68arg: volatile uint32_t* addr
69arg: uint32_t value
70test: none
71end:
72
73function: rsAtomicCas
74version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070075ret: int32_t, "Value of *addr prior to the operation."
Jean-Luc Brouillet6386ceb2015-04-28 15:06:30 -070076arg: volatile int32_t* addr, "Address of the value to compare and replace if the test passes."
77arg: int32_t compareValue, "Value to test *addr against."
78arg: int32_t newValue, "Value to write if the test passes."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070079summary: Thread-safe compare and set
80description:
81 If the value at addr matches compareValue then the newValue is written at addr,
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070082 i.e. <code>if (*addr == compareValue) { *addr = newValue; }</code>.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070083
84 You can check that the value was written by checking that the value returned
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070085 by rsAtomicCas() is compareValue.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070086test: none
87end:
88
89function: rsAtomicCas
90version: 14
91ret: uint32_t
92arg: volatile uint32_t* addr
93arg: uint32_t compareValue
94arg: uint32_t newValue
95test: none
96end:
97
98function: rsAtomicDec
99version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700100ret: int32_t, "Value of *addr prior to the operation."
101arg: volatile int32_t* addr, "Address of the value to decrement."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700102summary: Thread-safe decrement
103description:
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700104 Atomicly subtracts one from the value at addr. This is equivalent to <code>@rsAtomicSub(addr, 1)</code>.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700105test: none
106end:
107
108function: rsAtomicDec
109version: 20
110ret: int32_t
111arg: volatile uint32_t* addr
112test: none
113end:
114
115function: rsAtomicInc
116version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700117ret: int32_t, "Value of *addr prior to the operation."
118arg: volatile int32_t* addr, "Address of the value to increment."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700119summary: Thread-safe increment
120description:
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700121 Atomicly adds one to the value at addr. This is equivalent to <code>@rsAtomicAdd(addr, 1)</code>.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700122test: none
123end:
124
125function: rsAtomicInc
126version: 20
127ret: int32_t
128arg: volatile uint32_t* addr
129test: none
130end:
131
132function: rsAtomicMax
133version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700134ret: uint32_t, "Value of *addr prior to the operation."
135arg: volatile uint32_t* addr, "Address of the value to modify."
136arg: uint32_t value, "Comparison value."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700137summary: Thread-safe maximum
138description:
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700139 Atomicly sets the value at addr to the maximum of *addr and value, i.e.
140 <code>*addr = max(*addr, value)</code>.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700141test: none
142end:
143
144function: rsAtomicMax
145version: 14
146ret: int32_t
147arg: volatile int32_t* addr
148arg: int32_t value
149test: none
150end:
151
152function: rsAtomicMin
153version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700154ret: uint32_t, "Value of *addr prior to the operation."
155arg: volatile uint32_t* addr, "Address of the value to modify."
156arg: uint32_t value, "Comparison value."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700157summary: Thread-safe minimum
158description:
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700159 Atomicly sets the value at addr to the minimum of *addr and value, i.e.
160 <code>*addr = min(*addr, value)</code>.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700161test: none
162end:
163
164function: rsAtomicMin
165version: 14
166ret: int32_t
167arg: volatile int32_t* addr
168arg: int32_t value
169test: none
170end:
171
172function: rsAtomicOr
173version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700174ret: int32_t, "Value of *addr prior to the operation."
175arg: volatile int32_t* addr, "Address of the value to modify."
176arg: int32_t value, "Value to or with."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700177summary: Thread-safe bitwise or
178description:
179 Atomicly perform a bitwise or two values, storing the result at addr,
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700180 i.e. <code>*addr |= value</code>.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700181test: none
182end:
183
184function: rsAtomicOr
185version: 20
186ret: int32_t
187arg: volatile uint32_t* addr
188arg: uint32_t value
189test: none
190end:
191
192function: rsAtomicSub
193version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700194ret: int32_t, "Value of *addr prior to the operation."
195arg: volatile int32_t* addr, "Address of the value to modify."
196arg: int32_t value, "Amount to subtract."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700197summary: Thread-safe subtraction
198description:
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700199 Atomicly subtracts a value from the value at addr, i.e. <code>*addr -= value</code>.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700200test: none
201end:
202
203function: rsAtomicSub
204version: 20
205ret: int32_t
206arg: volatile uint32_t* addr
207arg: uint32_t value
208test: none
209end:
210
211function: rsAtomicXor
212version: 14
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700213ret: int32_t, "Value of *addr prior to the operation."
214arg: volatile int32_t* addr, "Address of the value to modify."
215arg: int32_t value, "Value to xor with."
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700216summary: Thread-safe bitwise exclusive or
217description:
218 Atomicly performs a bitwise xor of two values, storing the result at addr,
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700219 i.e. <code>*addr ^= value</code>.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700220test: none
221end:
222
223function: rsAtomicXor
224version: 20
225ret: int32_t
226arg: volatile uint32_t* addr
227arg: uint32_t value
228test: none
229end: