blob: 6c3a66f6bc2f1df4f57a0f0aa2ef08f4d075d219 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
2 * Copyright (C) 2008 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 */
Andy McFadden6a877082010-05-19 22:36:33 -070016
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080017/*
18 * Atomic operations
19 */
20#ifndef _DALVIK_ATOMIC
21#define _DALVIK_ATOMIC
22
Andy McFadden6a877082010-05-19 22:36:33 -070023#include <cutils/atomic.h> /* use common Android atomic ops */
24#include <cutils/atomic-inline.h> /* and some uncommon ones */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080025
26/*
Andy McFadden6a877082010-05-19 22:36:33 -070027 * NOTE: Two "quasiatomic" operations on the exact same memory address
28 * are guaranteed to operate atomically with respect to each other,
29 * but no guarantees are made about quasiatomic operations mixed with
30 * non-quasiatomic operations on the same address, nor about
31 * quasiatomic operations that are performed on partially-overlapping
32 * memory.
Andy McFadden6e10b9a2010-06-14 15:24:39 -070033 *
34 * None of these provide a memory barrier.
Andy McFadden6a877082010-05-19 22:36:33 -070035 */
36
37/*
Andy McFadden6e10b9a2010-06-14 15:24:39 -070038 * Swap the 64-bit value at "addr" with "value". Returns the previous
39 * value.
Andy McFadden6a877082010-05-19 22:36:33 -070040 */
Andy McFadden6e10b9a2010-06-14 15:24:39 -070041int64_t dvmQuasiAtomicSwap64(int64_t value, volatile int64_t* addr);
42
43/*
44 * Read the 64-bit value at "addr".
45 */
Andy McFaddenc35a2ef2010-06-17 12:36:00 -070046int64_t dvmQuasiAtomicRead64(volatile const int64_t* addr);
Andy McFadden6e10b9a2010-06-14 15:24:39 -070047
48/*
49 * If the value at "addr" is equal to "oldvalue", replace it with "newvalue"
50 * and return 0. Otherwise, don't swap, and return nonzero.
51 */
52int dvmQuasiAtomicCas64(int64_t oldvalue, int64_t newvalue,
Andy McFadden6a877082010-05-19 22:36:33 -070053 volatile int64_t* addr);
54
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080055#endif /*_DALVIK_ATOMIC*/