blob: dab625e4b653ef26b59ed6f206596e1909f3d19b [file] [log] [blame]
Elliott Hughes5ea047b2011-09-13 14:38:18 -07001/*
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 */
16
17#ifndef ART_SRC_ATOMIC_H_
18#define ART_SRC_ATOMIC_H_
19
20#include <cutils/atomic.h> /* use common Android atomic ops */
21#include <cutils/atomic-inline.h> /* and some uncommon ones */
22
23namespace art {
24
25/*
26 * NOTE: Two "quasiatomic" operations on the exact same memory address
27 * are guaranteed to operate atomically with respect to each other,
28 * but no guarantees are made about quasiatomic operations mixed with
29 * non-quasiatomic operations on the same address, nor about
30 * quasiatomic operations that are performed on partially-overlapping
31 * memory.
32 *
Elliott Hughes557e0272011-09-29 10:52:22 -070033 * Only the "Sync" functions provide a memory barrier.
Elliott Hughes5ea047b2011-09-13 14:38:18 -070034 */
35
36/*
37 * Swap the 64-bit value at "addr" with "value". Returns the previous
Elliott Hughes557e0272011-09-29 10:52:22 -070038 * value. No memory barriers.
Elliott Hughes5ea047b2011-09-13 14:38:18 -070039 */
40int64_t QuasiAtomicSwap64(int64_t value, volatile int64_t* addr);
41
42/*
Elliott Hughes557e0272011-09-29 10:52:22 -070043 * Swap the 64-bit value at "addr" with "value". Returns the previous
44 * value. Provides memory barriers.
45 */
46int64_t QuasiAtomicSwap64Sync(int64_t value, volatile int64_t* addr);
47
48/*
Elliott Hughes5ea047b2011-09-13 14:38:18 -070049 * Read the 64-bit value at "addr".
50 */
51int64_t QuasiAtomicRead64(volatile const int64_t* addr);
52
53/*
54 * If the value at "addr" is equal to "old_value", replace it with "new_value"
55 * and return 0. Otherwise, don't swap, and return nonzero.
56 */
57int QuasiAtomicCas64(int64_t old_value, int64_t new_value, volatile int64_t* addr);
58
59} // namespace art
60
61#endif // ART_SRC_ATOMIC_H_