rs_atomic.rsh revision c5184e202ced435258adb2cfe2013570e7190954
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
17// Don't edit this file!  It is auto-generated by frameworks/rs/api/gen_runtime.
18
19/*
20 * rs_atomic.rsh: Atomic routines
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 all done in the right order.
25 *
26 * These functions are slower than just doing the non-atomic variants, 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 */
35#ifndef RENDERSCRIPT_RS_ATOMIC_RSH
36#define RENDERSCRIPT_RS_ATOMIC_RSH
37
38/*
39 * rsAtomicAdd: Thread-safe addition
40 *
41 * Atomicly adds a value to the value at addr, i.e. *addr += value.
42 *
43 * Parameters:
44 *   addr Address of the value to modify
45 *   value Amount to add
46 *
47 * Returns: Old value
48 */
49#if (defined(RS_VERSION) && (RS_VERSION >= 14))
50extern int32_t __attribute__((overloadable))
51    rsAtomicAdd(volatile int32_t* addr, int32_t value);
52#endif
53
54#if (defined(RS_VERSION) && (RS_VERSION >= 20))
55extern int32_t __attribute__((overloadable))
56    rsAtomicAdd(volatile uint32_t* addr, uint32_t value);
57#endif
58
59/*
60 * rsAtomicAnd: Thread-safe bitwise and
61 *
62 * Atomicly performs a bitwise and of two values, storing the result back at addr,
63 * i.e. *addr &= value
64 *
65 * Parameters:
66 *   addr Address of the value to modify
67 *   value Value to and with
68 *
69 * Returns: Old value
70 */
71#if (defined(RS_VERSION) && (RS_VERSION >= 14))
72extern int32_t __attribute__((overloadable))
73    rsAtomicAnd(volatile int32_t* addr, int32_t value);
74#endif
75
76#if (defined(RS_VERSION) && (RS_VERSION >= 20))
77extern int32_t __attribute__((overloadable))
78    rsAtomicAnd(volatile uint32_t* addr, uint32_t value);
79#endif
80
81/*
82 * rsAtomicCas: Thread-safe compare and set
83 *
84 * If the value at addr matches compareValue then the newValue is written at addr,
85 * i.e. if (*addr == compareValue) { *addr = newValue; }
86 *
87 * You can check that the value was written by checking that the value returned
88 * by rsAtomicCas is compareValue.
89 *
90 * Parameters:
91 *   addr The address to compare and replace if the compare passes.
92 *   compareValue The value to test *addr against.
93 *   newValue The value to write if the test passes.
94 *
95 * Returns: Old value
96 */
97#if (defined(RS_VERSION) && (RS_VERSION >= 14))
98extern int32_t __attribute__((overloadable))
99    rsAtomicCas(volatile int32_t* addr, int32_t compareValue, int32_t newValue);
100#endif
101
102#if (defined(RS_VERSION) && (RS_VERSION >= 14))
103extern uint32_t __attribute__((overloadable))
104    rsAtomicCas(volatile uint32_t* addr, uint32_t compareValue, uint32_t newValue);
105#endif
106
107/*
108 * rsAtomicDec: Thread-safe decrement
109 *
110 * Atomicly subtracts one from the value at addr.  Equal to rsAtomicSub(addr, 1)
111 *
112 * Parameters:
113 *   addr Address of the value to decrement
114 *
115 * Returns: Old value
116 */
117#if (defined(RS_VERSION) && (RS_VERSION >= 14))
118extern int32_t __attribute__((overloadable))
119    rsAtomicDec(volatile int32_t* addr);
120#endif
121
122#if (defined(RS_VERSION) && (RS_VERSION >= 20))
123extern int32_t __attribute__((overloadable))
124    rsAtomicDec(volatile uint32_t* addr);
125#endif
126
127/*
128 * rsAtomicInc: Thread-safe increment
129 *
130 * Atomicly adds one to the value at addr.  Equal to rsAtomicAdd(addr, 1)
131 *
132 * Parameters:
133 *   addr Address of the value to increment
134 *
135 * Returns: Old value
136 */
137#if (defined(RS_VERSION) && (RS_VERSION >= 14))
138extern int32_t __attribute__((overloadable))
139    rsAtomicInc(volatile int32_t* addr);
140#endif
141
142#if (defined(RS_VERSION) && (RS_VERSION >= 20))
143extern int32_t __attribute__((overloadable))
144    rsAtomicInc(volatile uint32_t* addr);
145#endif
146
147/*
148 * rsAtomicMax: Thread-safe maximum
149 *
150 * Atomicly sets the value at addr to the maximum of addr and value, i.e.
151 * *addr = max(*addr, value)
152 *
153 * Parameters:
154 *   addr Address of the value to modify
155 *   value Comparison value
156 *
157 * Returns: Old value
158 */
159#if (defined(RS_VERSION) && (RS_VERSION >= 14))
160extern uint32_t __attribute__((overloadable))
161    rsAtomicMax(volatile uint32_t* addr, uint32_t value);
162#endif
163
164#if (defined(RS_VERSION) && (RS_VERSION >= 14))
165extern int32_t __attribute__((overloadable))
166    rsAtomicMax(volatile int32_t* addr, int32_t value);
167#endif
168
169/*
170 * rsAtomicMin: Thread-safe minimum
171 *
172 * Atomicly sets the value at addr to the minimum of addr and value, i.e.
173 * *addr = min(*addr, value)
174 *
175 * Parameters:
176 *   addr Address of the value to modify
177 *   value Comparison value
178 *
179 * Returns: Old value
180 */
181#if (defined(RS_VERSION) && (RS_VERSION >= 14))
182extern uint32_t __attribute__((overloadable))
183    rsAtomicMin(volatile uint32_t* addr, uint32_t value);
184#endif
185
186#if (defined(RS_VERSION) && (RS_VERSION >= 14))
187extern int32_t __attribute__((overloadable))
188    rsAtomicMin(volatile int32_t* addr, int32_t value);
189#endif
190
191/*
192 * rsAtomicOr: Thread-safe bitwise or
193 *
194 * Atomicly perform a bitwise or two values, storing the result at addr,
195 * i.e. *addr |= value
196 *
197 * Parameters:
198 *   addr Address of the value to modify
199 *   value Value to or with
200 *
201 * Returns: Old value
202 */
203#if (defined(RS_VERSION) && (RS_VERSION >= 14))
204extern int32_t __attribute__((overloadable))
205    rsAtomicOr(volatile int32_t* addr, int32_t value);
206#endif
207
208#if (defined(RS_VERSION) && (RS_VERSION >= 20))
209extern int32_t __attribute__((overloadable))
210    rsAtomicOr(volatile uint32_t* addr, uint32_t value);
211#endif
212
213/*
214 * rsAtomicSub: Thread-safe subtraction
215 *
216 * Atomicly subtracts a value from the value at addr, i.e. *addr -= value
217 *
218 * Parameters:
219 *   addr Address of the value to modify
220 *   value Amount to subtract
221 *
222 * Returns: Old value
223 */
224#if (defined(RS_VERSION) && (RS_VERSION >= 14))
225extern int32_t __attribute__((overloadable))
226    rsAtomicSub(volatile int32_t* addr, int32_t value);
227#endif
228
229#if (defined(RS_VERSION) && (RS_VERSION >= 20))
230extern int32_t __attribute__((overloadable))
231    rsAtomicSub(volatile uint32_t* addr, uint32_t value);
232#endif
233
234/*
235 * rsAtomicXor: Thread-safe bitwise exclusive or
236 *
237 * Atomicly performs a bitwise xor of two values, storing the result at addr,
238 * i.e. *addr ^= value
239 *
240 * Parameters:
241 *   addr Address of the value to modify
242 *   value Value to xor with
243 *
244 * Returns: Old value
245 */
246#if (defined(RS_VERSION) && (RS_VERSION >= 14))
247extern int32_t __attribute__((overloadable))
248    rsAtomicXor(volatile int32_t* addr, int32_t value);
249#endif
250
251#if (defined(RS_VERSION) && (RS_VERSION >= 20))
252extern int32_t __attribute__((overloadable))
253    rsAtomicXor(volatile uint32_t* addr, uint32_t value);
254#endif
255
256#endif // RENDERSCRIPT_RS_ATOMIC_RSH
257