blob: 0ab26ca4e7c42cd93509638c75e8686e47074ee9 [file] [log] [blame]
Ying Wangb335bb02011-11-29 10:23:55 -08001/*
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -07002 * Copyright (C) 2015 The Android Open Source Project
Ying Wangb335bb02011-11-29 10:23:55 -08003 *
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
Stephen Hines3f868232015-04-10 09:22:19 -070017// Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070018
19/*
Stephen Hines3f868232015-04-10 09:22:19 -070020 * rs_atomic.rsh: Atomic Update Functions
Ying Wangb335bb02011-11-29 10:23:55 -080021 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070022 * 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
Stephen Hines3f868232015-04-10 09:22:19 -070024 * reads, the updates, and the memory writes are done in the right order.
Ying Wangb335bb02011-11-29 10:23:55 -080025 *
Stephen Hines3f868232015-04-10 09:22:19 -070026 * These functions are slower than their non-atomic equivalents, so use
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070027 * 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.
Ying Wangb335bb02011-11-29 10:23:55 -080034 */
Stephen Hines3f868232015-04-10 09:22:19 -070035
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070036#ifndef RENDERSCRIPT_RS_ATOMIC_RSH
37#define RENDERSCRIPT_RS_ATOMIC_RSH
Ying Wangb335bb02011-11-29 10:23:55 -080038
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070039/*
40 * rsAtomicAdd: Thread-safe addition
41 *
42 * Atomicly adds a value to the value at addr, i.e. *addr += value.
43 *
44 * Parameters:
Stephen Hines3f868232015-04-10 09:22:19 -070045 * addr: Address of the value to modify.
46 * value: Amount to add.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070047 *
Stephen Hines3f868232015-04-10 09:22:19 -070048 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070049 */
Ying Wangb335bb02011-11-29 10:23:55 -080050#if (defined(RS_VERSION) && (RS_VERSION >= 14))
Ying Wangb335bb02011-11-29 10:23:55 -080051extern int32_t __attribute__((overloadable))
52 rsAtomicAdd(volatile int32_t* addr, int32_t value);
Ying Wangb335bb02011-11-29 10:23:55 -080053#endif
54
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070055#if (defined(RS_VERSION) && (RS_VERSION >= 20))
56extern int32_t __attribute__((overloadable))
57 rsAtomicAdd(volatile uint32_t* addr, uint32_t value);
58#endif
59
60/*
61 * rsAtomicAnd: Thread-safe bitwise and
62 *
63 * Atomicly performs a bitwise and of two values, storing the result back at addr,
Stephen Hines3f868232015-04-10 09:22:19 -070064 * i.e. *addr &= value.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070065 *
66 * Parameters:
Stephen Hines3f868232015-04-10 09:22:19 -070067 * addr: Address of the value to modify.
68 * value: Value to and with.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070069 *
Stephen Hines3f868232015-04-10 09:22:19 -070070 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070071 */
72#if (defined(RS_VERSION) && (RS_VERSION >= 14))
73extern int32_t __attribute__((overloadable))
74 rsAtomicAnd(volatile int32_t* addr, int32_t value);
75#endif
76
77#if (defined(RS_VERSION) && (RS_VERSION >= 20))
78extern int32_t __attribute__((overloadable))
79 rsAtomicAnd(volatile uint32_t* addr, uint32_t value);
80#endif
81
82/*
83 * rsAtomicCas: Thread-safe compare and set
84 *
85 * If the value at addr matches compareValue then the newValue is written at addr,
Stephen Hines3f868232015-04-10 09:22:19 -070086 * i.e. if (*addr == compareValue) { *addr = newValue; }.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070087 *
88 * You can check that the value was written by checking that the value returned
Stephen Hines3f868232015-04-10 09:22:19 -070089 * by rsAtomicCas() is compareValue.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070090 *
91 * Parameters:
Pirama Arumuga Nainardb745862015-05-11 14:34:37 -070092 * 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.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070095 *
Stephen Hines3f868232015-04-10 09:22:19 -070096 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070097 */
98#if (defined(RS_VERSION) && (RS_VERSION >= 14))
99extern int32_t __attribute__((overloadable))
100 rsAtomicCas(volatile int32_t* addr, int32_t compareValue, int32_t newValue);
101#endif
102
103#if (defined(RS_VERSION) && (RS_VERSION >= 14))
104extern uint32_t __attribute__((overloadable))
105 rsAtomicCas(volatile uint32_t* addr, uint32_t compareValue, uint32_t newValue);
106#endif
107
108/*
109 * rsAtomicDec: Thread-safe decrement
110 *
Stephen Hines3f868232015-04-10 09:22:19 -0700111 * Atomicly subtracts one from the value at addr. This is equivalent to rsAtomicSub(addr, 1).
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700112 *
113 * Parameters:
Stephen Hines3f868232015-04-10 09:22:19 -0700114 * addr: Address of the value to decrement.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700115 *
Stephen Hines3f868232015-04-10 09:22:19 -0700116 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700117 */
118#if (defined(RS_VERSION) && (RS_VERSION >= 14))
119extern int32_t __attribute__((overloadable))
120 rsAtomicDec(volatile int32_t* addr);
121#endif
122
123#if (defined(RS_VERSION) && (RS_VERSION >= 20))
124extern int32_t __attribute__((overloadable))
125 rsAtomicDec(volatile uint32_t* addr);
126#endif
127
128/*
129 * rsAtomicInc: Thread-safe increment
130 *
Stephen Hines3f868232015-04-10 09:22:19 -0700131 * Atomicly adds one to the value at addr. This is equivalent to rsAtomicAdd(addr, 1).
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700132 *
133 * Parameters:
Stephen Hines3f868232015-04-10 09:22:19 -0700134 * addr: Address of the value to increment.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700135 *
Stephen Hines3f868232015-04-10 09:22:19 -0700136 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700137 */
138#if (defined(RS_VERSION) && (RS_VERSION >= 14))
139extern int32_t __attribute__((overloadable))
140 rsAtomicInc(volatile int32_t* addr);
141#endif
142
143#if (defined(RS_VERSION) && (RS_VERSION >= 20))
144extern int32_t __attribute__((overloadable))
145 rsAtomicInc(volatile uint32_t* addr);
146#endif
147
148/*
149 * rsAtomicMax: Thread-safe maximum
150 *
Stephen Hines3f868232015-04-10 09:22:19 -0700151 * Atomicly sets the value at addr to the maximum of *addr and value, i.e.
152 * *addr = max(*addr, value).
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700153 *
154 * Parameters:
Stephen Hines3f868232015-04-10 09:22:19 -0700155 * addr: Address of the value to modify.
156 * value: Comparison value.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700157 *
Stephen Hines3f868232015-04-10 09:22:19 -0700158 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700159 */
160#if (defined(RS_VERSION) && (RS_VERSION >= 14))
161extern uint32_t __attribute__((overloadable))
162 rsAtomicMax(volatile uint32_t* addr, uint32_t value);
163#endif
164
165#if (defined(RS_VERSION) && (RS_VERSION >= 14))
166extern int32_t __attribute__((overloadable))
167 rsAtomicMax(volatile int32_t* addr, int32_t value);
168#endif
169
170/*
171 * rsAtomicMin: Thread-safe minimum
172 *
Stephen Hines3f868232015-04-10 09:22:19 -0700173 * Atomicly sets the value at addr to the minimum of *addr and value, i.e.
174 * *addr = min(*addr, value).
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700175 *
176 * Parameters:
Stephen Hines3f868232015-04-10 09:22:19 -0700177 * addr: Address of the value to modify.
178 * value: Comparison value.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700179 *
Stephen Hines3f868232015-04-10 09:22:19 -0700180 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700181 */
182#if (defined(RS_VERSION) && (RS_VERSION >= 14))
183extern uint32_t __attribute__((overloadable))
184 rsAtomicMin(volatile uint32_t* addr, uint32_t value);
185#endif
186
187#if (defined(RS_VERSION) && (RS_VERSION >= 14))
188extern int32_t __attribute__((overloadable))
189 rsAtomicMin(volatile int32_t* addr, int32_t value);
190#endif
191
192/*
193 * rsAtomicOr: Thread-safe bitwise or
194 *
195 * Atomicly perform a bitwise or two values, storing the result at addr,
Stephen Hines3f868232015-04-10 09:22:19 -0700196 * i.e. *addr |= value.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700197 *
198 * Parameters:
Stephen Hines3f868232015-04-10 09:22:19 -0700199 * addr: Address of the value to modify.
200 * value: Value to or with.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700201 *
Stephen Hines3f868232015-04-10 09:22:19 -0700202 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700203 */
204#if (defined(RS_VERSION) && (RS_VERSION >= 14))
205extern int32_t __attribute__((overloadable))
206 rsAtomicOr(volatile int32_t* addr, int32_t value);
207#endif
208
209#if (defined(RS_VERSION) && (RS_VERSION >= 20))
210extern int32_t __attribute__((overloadable))
211 rsAtomicOr(volatile uint32_t* addr, uint32_t value);
212#endif
213
214/*
215 * rsAtomicSub: Thread-safe subtraction
216 *
Stephen Hines3f868232015-04-10 09:22:19 -0700217 * Atomicly subtracts a value from the value at addr, i.e. *addr -= value.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700218 *
219 * Parameters:
Stephen Hines3f868232015-04-10 09:22:19 -0700220 * addr: Address of the value to modify.
221 * value: Amount to subtract.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700222 *
Stephen Hines3f868232015-04-10 09:22:19 -0700223 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700224 */
225#if (defined(RS_VERSION) && (RS_VERSION >= 14))
226extern int32_t __attribute__((overloadable))
227 rsAtomicSub(volatile int32_t* addr, int32_t value);
228#endif
229
230#if (defined(RS_VERSION) && (RS_VERSION >= 20))
231extern int32_t __attribute__((overloadable))
232 rsAtomicSub(volatile uint32_t* addr, uint32_t value);
233#endif
234
235/*
236 * rsAtomicXor: Thread-safe bitwise exclusive or
237 *
238 * Atomicly performs a bitwise xor of two values, storing the result at addr,
Stephen Hines3f868232015-04-10 09:22:19 -0700239 * i.e. *addr ^= value.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700240 *
241 * Parameters:
Stephen Hines3f868232015-04-10 09:22:19 -0700242 * addr: Address of the value to modify.
243 * value: Value to xor with.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700244 *
Stephen Hines3f868232015-04-10 09:22:19 -0700245 * Returns: Value of *addr prior to the operation.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700246 */
247#if (defined(RS_VERSION) && (RS_VERSION >= 14))
248extern int32_t __attribute__((overloadable))
249 rsAtomicXor(volatile int32_t* addr, int32_t value);
250#endif
251
252#if (defined(RS_VERSION) && (RS_VERSION >= 20))
253extern int32_t __attribute__((overloadable))
254 rsAtomicXor(volatile uint32_t* addr, uint32_t value);
255#endif
256
257#endif // RENDERSCRIPT_RS_ATOMIC_RSH