Home | History | Annotate | Download | only in vm
      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 /*
     18  * Atomic operations
     19  */
     20 #ifndef DALVIK_ATOMIC_H_
     21 #define DALVIK_ATOMIC_H_
     22 
     23 #include <cutils/atomic.h>          /* use common Android atomic ops */
     24 #include <cutils/atomic-inline.h>   /* and some uncommon ones */
     25 
     26 /*
     27  * 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.
     33  *
     34  * Only the "Sync" versions of these provide a memory barrier.
     35  */
     36 
     37 /*
     38  * Swap the 64-bit value at "addr" with "value".  Returns the previous
     39  * value.
     40  */
     41 extern "C" int64_t dvmQuasiAtomicSwap64(int64_t value, volatile int64_t* addr);
     42 
     43 /*
     44  * Swap the 64-bit value at "addr" with "value".  Returns the previous
     45  * value.  Provides memory barriers.
     46  */
     47 extern "C" int64_t dvmQuasiAtomicSwap64Sync(int64_t value,
     48                                             volatile int64_t* addr);
     49 
     50 /*
     51  * Read the 64-bit value at "addr".
     52  */
     53 extern "C" int64_t dvmQuasiAtomicRead64(volatile const int64_t* addr);
     54 
     55 /*
     56  * If the value at "addr" is equal to "oldvalue", replace it with "newvalue"
     57  * and return 0.  Otherwise, don't swap, and return nonzero.
     58  */
     59 int dvmQuasiAtomicCas64(int64_t oldvalue, int64_t newvalue,
     60         volatile int64_t* addr);
     61 
     62 #endif  // DALVIK_ATOMIC_H_
     63