Android O SDK.
[android_tools.git] / sdk / build-tools / 26.0.0 / renderscript / include / rs_atomic.rsh
blob98a8784067d320f270994d2f4dd6de37df7223ba
1 /*
2  * Copyright (C) 2016 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  */
17 // Don't edit this file!  It is auto-generated by frameworks/rs/api/generate.sh.
20  * rs_atomic.rsh: Atomic Update Functions
21  *
22  * To update values shared between multiple threads, use the functions below.
23  * They ensure that the values are atomically updated, i.e. that the memory
24  * reads, the updates, and the memory writes are done in the right order.
25  *
26  * These functions are slower than their non-atomic equivalents, so use
27  * them only when synchronization is needed.
28  *
29  * Note that in RenderScript, your code is likely to be running in separate
30  * threads even though you did not explicitely create them.  The RenderScript
31  * runtime will very often split the execution of one kernel across multiple
32  * threads.  Updating globals should be done with atomic functions.  If possible,
33  * modify your algorithm to avoid them altogether.
34  */
36 #ifndef RENDERSCRIPT_RS_ATOMIC_RSH
37 #define RENDERSCRIPT_RS_ATOMIC_RSH
40  * rsAtomicAdd: Thread-safe addition
41  *
42  * Atomicly adds a value to the value at addr, i.e. *addr += value.
43  *
44  * Parameters:
45  *   addr: Address of the value to modify.
46  *   value: Amount to add.
47  *
48  * Returns: Value of *addr prior to the operation.
49  */
50 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
51 extern int32_t __attribute__((overloadable))
52     rsAtomicAdd(volatile int32_t* addr, int32_t value);
53 #endif
55 #if (defined(RS_VERSION) && (RS_VERSION >= 20))
56 extern int32_t __attribute__((overloadable))
57     rsAtomicAdd(volatile uint32_t* addr, uint32_t value);
58 #endif
61  * rsAtomicAnd: Thread-safe bitwise and
62  *
63  * Atomicly performs a bitwise and of two values, storing the result back at addr,
64  * i.e. *addr &= value.
65  *
66  * Parameters:
67  *   addr: Address of the value to modify.
68  *   value: Value to and with.
69  *
70  * Returns: Value of *addr prior to the operation.
71  */
72 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
73 extern int32_t __attribute__((overloadable))
74     rsAtomicAnd(volatile int32_t* addr, int32_t value);
75 #endif
77 #if (defined(RS_VERSION) && (RS_VERSION >= 20))
78 extern int32_t __attribute__((overloadable))
79     rsAtomicAnd(volatile uint32_t* addr, uint32_t value);
80 #endif
83  * rsAtomicCas: Thread-safe compare and set
84  *
85  * If the value at addr matches compareValue then the newValue is written at addr,
86  * i.e. if (*addr == compareValue) { *addr = newValue; }.
87  *
88  * You can check that the value was written by checking that the value returned
89  * by rsAtomicCas() is compareValue.
90  *
91  * Parameters:
92  *   addr: Address of the value to compare and replace if the test passes.
93  *   compareValue: Value to test *addr against.
94  *   newValue: Value to write if the test passes.
95  *
96  * Returns: Value of *addr prior to the operation.
97  */
98 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
99 extern int32_t __attribute__((overloadable))
100     rsAtomicCas(volatile int32_t* addr, int32_t compareValue, int32_t newValue);
101 #endif
103 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
104 extern uint32_t __attribute__((overloadable))
105     rsAtomicCas(volatile uint32_t* addr, uint32_t compareValue, uint32_t newValue);
106 #endif
109  * rsAtomicDec: Thread-safe decrement
111  * Atomicly subtracts one from the value at addr.  This is equivalent to rsAtomicSub(addr, 1).
113  * Parameters:
114  *   addr: Address of the value to decrement.
116  * Returns: Value of *addr prior to the operation.
117  */
118 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
119 extern int32_t __attribute__((overloadable))
120     rsAtomicDec(volatile int32_t* addr);
121 #endif
123 #if (defined(RS_VERSION) && (RS_VERSION >= 20))
124 extern int32_t __attribute__((overloadable))
125     rsAtomicDec(volatile uint32_t* addr);
126 #endif
129  * rsAtomicInc: Thread-safe increment
131  * Atomicly adds one to the value at addr.  This is equivalent to rsAtomicAdd(addr, 1).
133  * Parameters:
134  *   addr: Address of the value to increment.
136  * Returns: Value of *addr prior to the operation.
137  */
138 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
139 extern int32_t __attribute__((overloadable))
140     rsAtomicInc(volatile int32_t* addr);
141 #endif
143 #if (defined(RS_VERSION) && (RS_VERSION >= 20))
144 extern int32_t __attribute__((overloadable))
145     rsAtomicInc(volatile uint32_t* addr);
146 #endif
149  * rsAtomicMax: Thread-safe maximum
151  * Atomicly sets the value at addr to the maximum of *addr and value, i.e.
152  * *addr = max(*addr, value).
154  * Parameters:
155  *   addr: Address of the value to modify.
156  *   value: Comparison value.
158  * Returns: Value of *addr prior to the operation.
159  */
160 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
161 extern uint32_t __attribute__((overloadable))
162     rsAtomicMax(volatile uint32_t* addr, uint32_t value);
163 #endif
165 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
166 extern int32_t __attribute__((overloadable))
167     rsAtomicMax(volatile int32_t* addr, int32_t value);
168 #endif
171  * rsAtomicMin: Thread-safe minimum
173  * Atomicly sets the value at addr to the minimum of *addr and value, i.e.
174  * *addr = min(*addr, value).
176  * Parameters:
177  *   addr: Address of the value to modify.
178  *   value: Comparison value.
180  * Returns: Value of *addr prior to the operation.
181  */
182 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
183 extern uint32_t __attribute__((overloadable))
184     rsAtomicMin(volatile uint32_t* addr, uint32_t value);
185 #endif
187 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
188 extern int32_t __attribute__((overloadable))
189     rsAtomicMin(volatile int32_t* addr, int32_t value);
190 #endif
193  * rsAtomicOr: Thread-safe bitwise or
195  * Atomicly perform a bitwise or two values, storing the result at addr,
196  * i.e. *addr |= value.
198  * Parameters:
199  *   addr: Address of the value to modify.
200  *   value: Value to or with.
202  * Returns: Value of *addr prior to the operation.
203  */
204 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
205 extern int32_t __attribute__((overloadable))
206     rsAtomicOr(volatile int32_t* addr, int32_t value);
207 #endif
209 #if (defined(RS_VERSION) && (RS_VERSION >= 20))
210 extern int32_t __attribute__((overloadable))
211     rsAtomicOr(volatile uint32_t* addr, uint32_t value);
212 #endif
215  * rsAtomicSub: Thread-safe subtraction
217  * Atomicly subtracts a value from the value at addr, i.e. *addr -= value.
219  * Parameters:
220  *   addr: Address of the value to modify.
221  *   value: Amount to subtract.
223  * Returns: Value of *addr prior to the operation.
224  */
225 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
226 extern int32_t __attribute__((overloadable))
227     rsAtomicSub(volatile int32_t* addr, int32_t value);
228 #endif
230 #if (defined(RS_VERSION) && (RS_VERSION >= 20))
231 extern int32_t __attribute__((overloadable))
232     rsAtomicSub(volatile uint32_t* addr, uint32_t value);
233 #endif
236  * rsAtomicXor: Thread-safe bitwise exclusive or
238  * Atomicly performs a bitwise xor of two values, storing the result at addr,
239  * i.e. *addr ^= value.
241  * Parameters:
242  *   addr: Address of the value to modify.
243  *   value: Value to xor with.
245  * Returns: Value of *addr prior to the operation.
246  */
247 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
248 extern int32_t __attribute__((overloadable))
249     rsAtomicXor(volatile int32_t* addr, int32_t value);
250 #endif
252 #if (defined(RS_VERSION) && (RS_VERSION >= 20))
253 extern int32_t __attribute__((overloadable))
254     rsAtomicXor(volatile uint32_t* addr, uint32_t value);
255 #endif
257 #endif // RENDERSCRIPT_RS_ATOMIC_RSH