• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
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:
18summary: Atomic Update Functions
19description:
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
22 reads, the updates, and the memory writes are done in the right order.
23
24 These functions are slower than their non-atomic equivalents, so use
25 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
36ret: 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."
39summary: 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
55ret: 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."
58summary: Thread-safe bitwise and
59description:
60 Atomicly performs a bitwise and of two values, storing the result back at addr,
61 i.e. <code>*addr &amp;= value</code>.
62test: 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
75ret: int32_t, "Value of *addr prior to the operation."
76arg: 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."
79summary: Thread-safe compare and set
80description:
81 If the value at addr matches compareValue then the newValue is written at addr,
82 i.e. <code>if (*addr == compareValue) { *addr = newValue; }</code>.
83
84 You can check that the value was written by checking that the value returned
85 by rsAtomicCas() is compareValue.
86test: 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
100ret: int32_t, "Value of *addr prior to the operation."
101arg: volatile int32_t* addr, "Address of the value to decrement."
102summary: Thread-safe decrement
103description:
104 Atomicly subtracts one from the value at addr.  This is equivalent to <code>@rsAtomicSub(addr, 1)</code>.
105test: none
106end:
107
108function: rsAtomicDec
109version: 20
110ret: int32_t
111arg: volatile uint32_t* addr
112test: none
113end:
114
115function: rsAtomicInc
116version: 14
117ret: int32_t, "Value of *addr prior to the operation."
118arg: volatile int32_t* addr, "Address of the value to increment."
119summary: Thread-safe increment
120description:
121 Atomicly adds one to the value at addr.  This is equivalent to <code>@rsAtomicAdd(addr, 1)</code>.
122test: none
123end:
124
125function: rsAtomicInc
126version: 20
127ret: int32_t
128arg: volatile uint32_t* addr
129test: none
130end:
131
132function: rsAtomicMax
133version: 14
134ret: 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."
137summary: Thread-safe maximum
138description:
139 Atomicly sets the value at addr to the maximum of *addr and value, i.e.
140 <code>*addr = max(*addr, value)</code>.
141test: 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
154ret: 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."
157summary: Thread-safe minimum
158description:
159 Atomicly sets the value at addr to the minimum of *addr and value, i.e.
160 <code>*addr = min(*addr, value)</code>.
161test: 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
174ret: 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."
177summary: Thread-safe bitwise or
178description:
179 Atomicly perform a bitwise or two values, storing the result at addr,
180 i.e. <code>*addr |= value</code>.
181test: 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
194ret: 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."
197summary: Thread-safe subtraction
198description:
199 Atomicly subtracts a value from the value at addr, i.e. <code>*addr -= value</code>.
200test: 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
213ret: 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."
216summary: Thread-safe bitwise exclusive or
217description:
218 Atomicly performs a bitwise xor of two values, storing the result at addr,
219 i.e. <code>*addr ^= value</code>.
220test: none
221end:
222
223function: rsAtomicXor
224version: 20
225ret: int32_t
226arg: volatile uint32_t* addr
227arg: uint32_t value
228test: none
229end:
230