OSDN Git Service

Merge change 23193 into eclair
[android-x86/dalvik.git] / vm / Atomic.h
1 /*
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  * Atomic operations
18  */
19 #ifndef _DALVIK_ATOMIC
20 #define _DALVIK_ATOMIC
21
22 #include <utils/Atomic.h>       /* use common Android atomic ops */
23
24 /*
25  * Memory barrier.  Guarantee that register-resident variables
26  * are flushed to memory, and guarantee that instructions before
27  * the barrier do not get reordered to appear past it.
28  *
29  * 'asm volatile ("":::"memory")' is probably overkill, but it's correct.
30  * There may be a way to do it that doesn't flush every single register.
31  *
32  * TODO: look into the wmb() family on Linux and equivalents on other systems.
33  */
34 #define MEM_BARRIER()   do { asm volatile ("":::"memory"); } while (0)
35
36 /*
37  * Atomic compare-and-swap macro.
38  *
39  * If *_addr equals "_old", replace it with "_new" and return 1.  Otherwise
40  * return 0.  (e.g. x86 "cmpxchgl" instruction.)
41  *
42  * Underlying function is currently declared:
43  * int android_atomic_cmpxchg(int32_t old, int32_t new, volatile int32_t* addr)
44  */
45 #define ATOMIC_CMP_SWAP(_addr, _old, _new) \
46             (android_atomic_cmpxchg((_old), (_new), (_addr)) == 0)
47
48 #endif /*_DALVIK_ATOMIC*/