Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2011 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 /** @file rs_atomic.rsh
     18  *  \brief Atomic routines
     19  *
     20  *
     21  */
     22 
     23 #ifndef __RS_ATOMIC_RSH__
     24 #define __RS_ATOMIC_RSH__
     25 
     26 
     27 /**
     28  * Atomic add one to the value at addr.
     29  * Equal to rsAtomicAdd(addr, 1)
     30  *
     31  * @param addr Address of value to increment
     32  *
     33  * @return old value
     34  */
     35 extern int32_t __attribute__((overloadable))
     36     rsAtomicInc(volatile int32_t* addr);
     37 /**
     38  * Atomic add one to the value at addr.
     39  * Equal to rsAtomicAdd(addr, 1)
     40  *
     41  * @param addr Address of value to increment
     42  *
     43  * @return old value
     44  */
     45 extern uint32_t __attribute__((overloadable))
     46     rsAtomicInc(volatile uint32_t* addr);
     47 
     48 /**
     49  * Atomic subtract one from the value at addr. Equal to rsAtomicSub(addr, 1)
     50  *
     51  * @param addr Address of value to decrement
     52  *
     53  * @return old value
     54  */
     55 extern int32_t __attribute__((overloadable))
     56     rsAtomicDec(volatile int32_t* addr);
     57 /**
     58  * Atomic subtract one from the value at addr. Equal to rsAtomicSub(addr, 1)
     59  *
     60  * @param addr Address of value to decrement
     61  *
     62  * @return old value
     63  */
     64 extern uint32_t __attribute__((overloadable))
     65     rsAtomicDec(volatile uint32_t* addr);
     66 
     67 /**
     68  * Atomic add a value to the value at addr.  addr[0] += value
     69  *
     70  * @param addr Address of value to modify
     71  * @param value Amount to add to the value at addr
     72  *
     73  * @return old value
     74  */
     75 extern int32_t __attribute__((overloadable))
     76     rsAtomicAdd(volatile int32_t* addr, int32_t value);
     77 /**
     78  * Atomic add a value to the value at addr.  addr[0] += value
     79  *
     80  * @param addr Address of value to modify
     81  * @param value Amount to add to the value at addr
     82  *
     83  * @return old value
     84  */
     85 extern uint32_t __attribute__((overloadable))
     86     rsAtomicAdd(volatile uint32_t* addr, uint32_t value);
     87 
     88 /**
     89  * Atomic Subtract a value from the value at addr.  addr[0] -= value
     90  *
     91  * @param addr Address of value to modify
     92  * @param value Amount to subtract from the value at addr
     93  *
     94  * @return old value
     95  */
     96 extern int32_t __attribute__((overloadable))
     97     rsAtomicSub(volatile int32_t* addr, int32_t value);
     98 /**
     99  * Atomic Subtract a value from the value at addr.  addr[0] -= value
    100  *
    101  * @param addr Address of value to modify
    102  * @param value Amount to subtract from the value at addr
    103  *
    104  * @return old value
    105  */
    106 extern uint32_t __attribute__((overloadable))
    107     rsAtomicSub(volatile uint32_t* addr, uint32_t value);
    108 
    109 /**
    110  * Atomic Bitwise and a value from the value at addr.  addr[0] &= value
    111  *
    112  * @param addr Address of value to modify
    113  * @param value Amount to and with the value at addr
    114  *
    115  * @return old value
    116  */
    117 extern int32_t __attribute__((overloadable))
    118     rsAtomicAnd(volatile int32_t* addr, int32_t value);
    119 /**
    120  * Atomic Bitwise and a value from the value at addr.  addr[0] &= value
    121  *
    122  * @param addr Address of value to modify
    123  * @param value Amount to and with the value at addr
    124  *
    125  * @return old value
    126  */
    127 extern uint32_t __attribute__((overloadable))
    128     rsAtomicAnd(volatile uint32_t* addr, uint32_t value);
    129 
    130 /**
    131  * Atomic Bitwise or a value from the value at addr.  addr[0] |= value
    132  *
    133  * @param addr Address of value to modify
    134  * @param value Amount to or with the value at addr
    135  *
    136  * @return old value
    137  */
    138 extern int32_t __attribute__((overloadable))
    139     rsAtomicOr(volatile int32_t* addr, int32_t value);
    140 /**
    141  * Atomic Bitwise or a value from the value at addr.  addr[0] |= value
    142  *
    143  * @param addr Address of value to modify
    144  * @param value Amount to or with the value at addr
    145  *
    146  * @return old value
    147  */
    148 extern uint32_t __attribute__((overloadable))
    149     rsAtomicOr(volatile uint32_t* addr, uint32_t value);
    150 
    151 /**
    152  * Atomic Bitwise xor a value from the value at addr.  addr[0] ^= value
    153  *
    154  * @param addr Address of value to modify
    155  * @param value Amount to xor with the value at addr
    156  *
    157  * @return old value
    158  */
    159 extern uint32_t __attribute__((overloadable))
    160     rsAtomicXor(volatile uint32_t* addr, uint32_t value);
    161 /**
    162  * Atomic Bitwise xor a value from the value at addr.  addr[0] ^= value
    163  *
    164  * @param addr Address of value to modify
    165  * @param value Amount to xor with the value at addr
    166  *
    167  * @return old value
    168  */
    169 extern int32_t __attribute__((overloadable))
    170     rsAtomicXor(volatile int32_t* addr, int32_t value);
    171 
    172 /**
    173  * Atomic Set the value at addr to the min of addr and value
    174  * addr[0] = rsMin(addr[0], value)
    175  *
    176  * @param addr Address of value to modify
    177  * @param value comparison value
    178  *
    179  * @return old value
    180  */
    181 extern uint32_t __attribute__((overloadable))
    182     rsAtomicMin(volatile uint32_t* addr, uint32_t value);
    183 /**
    184  * Atomic Set the value at addr to the min of addr and value
    185  * addr[0] = rsMin(addr[0], value)
    186  *
    187  * @param addr Address of value to modify
    188  * @param value comparison value
    189  *
    190  * @return old value
    191  */
    192 extern int32_t __attribute__((overloadable))
    193     rsAtomicMin(volatile int32_t* addr, int32_t value);
    194 
    195 /**
    196  * Atomic Set the value at addr to the max of addr and value
    197  * addr[0] = rsMax(addr[0], value)
    198  *
    199  * @param addr Address of value to modify
    200  * @param value comparison value
    201  *
    202  * @return old value
    203  */
    204 extern uint32_t __attribute__((overloadable))
    205     rsAtomicMax(volatile uint32_t* addr, uint32_t value);
    206 /**
    207  * Atomic Set the value at addr to the max of addr and value
    208  * addr[0] = rsMin(addr[0], value)
    209  *
    210  * @param addr Address of value to modify
    211  * @param value comparison value
    212  *
    213  * @return old value
    214  */
    215 extern int32_t __attribute__((overloadable))
    216     rsAtomicMax(volatile int32_t* addr, int32_t value);
    217 
    218 /**
    219  * Compare-and-set operation with a full memory barrier.
    220  *
    221  * If the value at addr matches compareValue then newValue is written.
    222  *
    223  * @param addr The address to compare and replace if the compare passes.
    224  * @param compareValue The value to test addr[0] against.
    225  * @param newValue The value to write if the test passes.
    226  *
    227  * @return old value
    228  */
    229 extern int32_t __attribute__((overloadable))
    230     rsAtomicCas(volatile int32_t* addr, int32_t compareValue, int32_t newValue);
    231 
    232 /**
    233  * Compare-and-set operation with a full memory barrier.
    234  *
    235  * If the value at addr matches compareValue then newValue is written.
    236  *
    237  * @param addr The address to compare and replace if the compare passes.
    238  * @param compareValue The value to test addr[0] against.
    239  * @param newValue The value to write if the test passes.
    240  *
    241  * @return old value
    242  */
    243 extern uint32_t __attribute__((overloadable))
    244     rsAtomicCas(volatile uint32_t* addr, int32_t compareValue, int32_t newValue);
    245 
    246 
    247 #endif
    248 
    249