1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2013-2016. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. The name of the author may not be used to endorse or promote 13 * products derived from this software without specific prior 14 * written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Description: define atomic type and function 29 * Author: none 30 * Create: 2013 31 */ 32 33 #ifndef __ASM_ATOMIC_H__ 34 #define __ASM_ATOMIC_H__ 35 36 #include "los_atomic.h" 37 38 #ifdef __cplusplus 39 #if __cplusplus 40 extern "C" { 41 #endif /* __cplusplus */ 42 #endif /* __cplusplus */ 43 44 #ifdef __LP64__ 45 #define atomic_t long 46 #else 47 #define atomic_t int 48 #endif 49 50 #define atomic_inc(atom) LOS_AtomicInc(atom) 51 #define atomic_dec(atom) LOS_AtomicDec(atom) 52 #define atomic_sub(n, v) LOS_AtomicSub(v, n) 53 #define atomic_add(n, v) LOS_AtomicAdd(v, n) 54 #define atomic_read(atom) (*((volatile typeof(atom))(atom))) 55 #ifdef __LP64__ 56 #define atomic_set(p, v) LOS_AtomicXchg64bits(p, v) 57 #else 58 #define atomic_set(p, v) LOS_AtomicXchg32bits(p, v) 59 #endif 60 #define ATOMIC_INIT(x) (x) 61 62 #define atomic_add_return(i, v) LOS_AtomicAdd(v, i) 63 #define atomic_inc_return(v) LOS_AtomicIncRet(v) 64 #define atomic_dec_return(v) LOS_AtomicDecRet(v) 65 #define atomic_dec_and_test(v) (atomic_dec_return(v) == 0) 66 67 #ifdef __cplusplus 68 #if __cplusplus 69 } 70 #endif /* __cplusplus */ 71 #endif /* __cplusplus */ 72 73 #endif /* __ASM_ATOMIC_H__ */ 74