Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* atomic.h: Thankfully the V9 is at least reasonable for this
0003  *           stuff.
0004  *
0005  * Copyright (C) 1996, 1997, 2000, 2012 David S. Miller (davem@redhat.com)
0006  */
0007 
0008 #ifndef __ARCH_SPARC64_ATOMIC__
0009 #define __ARCH_SPARC64_ATOMIC__
0010 
0011 #include <linux/types.h>
0012 #include <asm/cmpxchg.h>
0013 #include <asm/barrier.h>
0014 
0015 #define ATOMIC64_INIT(i)    { (i) }
0016 
0017 #define arch_atomic_read(v) READ_ONCE((v)->counter)
0018 #define arch_atomic64_read(v)   READ_ONCE((v)->counter)
0019 
0020 #define arch_atomic_set(v, i)   WRITE_ONCE(((v)->counter), (i))
0021 #define arch_atomic64_set(v, i) WRITE_ONCE(((v)->counter), (i))
0022 
0023 #define ATOMIC_OP(op)                           \
0024 void arch_atomic_##op(int, atomic_t *);                 \
0025 void arch_atomic64_##op(s64, atomic64_t *);
0026 
0027 #define ATOMIC_OP_RETURN(op)                        \
0028 int arch_atomic_##op##_return(int, atomic_t *);             \
0029 s64 arch_atomic64_##op##_return(s64, atomic64_t *);
0030 
0031 #define ATOMIC_FETCH_OP(op)                     \
0032 int arch_atomic_fetch_##op(int, atomic_t *);                \
0033 s64 arch_atomic64_fetch_##op(s64, atomic64_t *);
0034 
0035 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op) ATOMIC_FETCH_OP(op)
0036 
0037 ATOMIC_OPS(add)
0038 ATOMIC_OPS(sub)
0039 
0040 #undef ATOMIC_OPS
0041 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_FETCH_OP(op)
0042 
0043 ATOMIC_OPS(and)
0044 ATOMIC_OPS(or)
0045 ATOMIC_OPS(xor)
0046 
0047 #undef ATOMIC_OPS
0048 #undef ATOMIC_FETCH_OP
0049 #undef ATOMIC_OP_RETURN
0050 #undef ATOMIC_OP
0051 
0052 #define arch_atomic_cmpxchg(v, o, n) (arch_cmpxchg(&((v)->counter), (o), (n)))
0053 
0054 static inline int arch_atomic_xchg(atomic_t *v, int new)
0055 {
0056     return arch_xchg(&v->counter, new);
0057 }
0058 
0059 #define arch_atomic64_cmpxchg(v, o, n) \
0060     ((__typeof__((v)->counter))arch_cmpxchg(&((v)->counter), (o), (n)))
0061 #define arch_atomic64_xchg(v, new) (arch_xchg(&((v)->counter), new))
0062 
0063 s64 arch_atomic64_dec_if_positive(atomic64_t *v);
0064 #define arch_atomic64_dec_if_positive arch_atomic64_dec_if_positive
0065 
0066 #endif /* !(__ARCH_SPARC64_ATOMIC__) */