atomic.h revision 5ea047b386c5dac78eda62305d14dedf7b5611a8
15ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes/* 25ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * Copyright (C) 2008 The Android Open Source Project 35ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * 45ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 55ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * you may not use this file except in compliance with the License. 65ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * You may obtain a copy of the License at 75ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * 85ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 95ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * 105ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * Unless required by applicable law or agreed to in writing, software 115ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 125ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * See the License for the specific language governing permissions and 145ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * limitations under the License. 155ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes */ 165ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes 175ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes#ifndef ART_SRC_ATOMIC_H_ 185ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes#define ART_SRC_ATOMIC_H_ 195ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes 205ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes#include <cutils/atomic.h> /* use common Android atomic ops */ 215ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes#include <cutils/atomic-inline.h> /* and some uncommon ones */ 225ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes 235ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughesnamespace art { 245ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes 255ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes/* 265ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * NOTE: Two "quasiatomic" operations on the exact same memory address 275ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * are guaranteed to operate atomically with respect to each other, 285ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * but no guarantees are made about quasiatomic operations mixed with 295ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * non-quasiatomic operations on the same address, nor about 305ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * quasiatomic operations that are performed on partially-overlapping 315ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * memory. 325ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * 335ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * None of these provide a memory barrier. 345ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes */ 355ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes 365ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes/* 375ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * Swap the 64-bit value at "addr" with "value". Returns the previous 385ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * value. 395ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes */ 405ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughesint64_t QuasiAtomicSwap64(int64_t value, volatile int64_t* addr); 415ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes 425ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes/* 435ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * Read the 64-bit value at "addr". 445ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes */ 455ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughesint64_t QuasiAtomicRead64(volatile const int64_t* addr); 465ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes 475ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes/* 485ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * If the value at "addr" is equal to "old_value", replace it with "new_value" 495ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes * and return 0. Otherwise, don't swap, and return nonzero. 505ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes */ 515ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughesint QuasiAtomicCas64(int64_t old_value, int64_t new_value, volatile int64_t* addr); 525ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes 535ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes} // namespace art 545ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes 555ea047b386c5dac78eda62305d14dedf7b5611a8Elliott Hughes#endif // ART_SRC_ATOMIC_H_ 56