0001
0002
0003 #ifndef _ASM_ARC_ATOMIC_SPLOCK_H
0004 #define _ASM_ARC_ATOMIC_SPLOCK_H
0005
0006
0007
0008
0009
0010
0011 static inline void arch_atomic_set(atomic_t *v, int i)
0012 {
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 unsigned long flags;
0023
0024 atomic_ops_lock(flags);
0025 WRITE_ONCE(v->counter, i);
0026 atomic_ops_unlock(flags);
0027 }
0028
0029 #define arch_atomic_set_release(v, i) arch_atomic_set((v), (i))
0030
0031 #define ATOMIC_OP(op, c_op, asm_op) \
0032 static inline void arch_atomic_##op(int i, atomic_t *v) \
0033 { \
0034 unsigned long flags; \
0035 \
0036 atomic_ops_lock(flags); \
0037 v->counter c_op i; \
0038 atomic_ops_unlock(flags); \
0039 }
0040
0041 #define ATOMIC_OP_RETURN(op, c_op, asm_op) \
0042 static inline int arch_atomic_##op##_return(int i, atomic_t *v) \
0043 { \
0044 unsigned long flags; \
0045 unsigned int temp; \
0046 \
0047
0048
0049 \
0050 atomic_ops_lock(flags); \
0051 temp = v->counter; \
0052 temp c_op i; \
0053 v->counter = temp; \
0054 atomic_ops_unlock(flags); \
0055 \
0056 return temp; \
0057 }
0058
0059 #define ATOMIC_FETCH_OP(op, c_op, asm_op) \
0060 static inline int arch_atomic_fetch_##op(int i, atomic_t *v) \
0061 { \
0062 unsigned long flags; \
0063 unsigned int orig; \
0064 \
0065
0066
0067 \
0068 atomic_ops_lock(flags); \
0069 orig = v->counter; \
0070 v->counter c_op i; \
0071 atomic_ops_unlock(flags); \
0072 \
0073 return orig; \
0074 }
0075
0076 #define ATOMIC_OPS(op, c_op, asm_op) \
0077 ATOMIC_OP(op, c_op, asm_op) \
0078 ATOMIC_OP_RETURN(op, c_op, asm_op) \
0079 ATOMIC_FETCH_OP(op, c_op, asm_op)
0080
0081 ATOMIC_OPS(add, +=, add)
0082 ATOMIC_OPS(sub, -=, sub)
0083
0084 #undef ATOMIC_OPS
0085 #define ATOMIC_OPS(op, c_op, asm_op) \
0086 ATOMIC_OP(op, c_op, asm_op) \
0087 ATOMIC_FETCH_OP(op, c_op, asm_op)
0088
0089 ATOMIC_OPS(and, &=, and)
0090 ATOMIC_OPS(andnot, &= ~, bic)
0091 ATOMIC_OPS(or, |=, or)
0092 ATOMIC_OPS(xor, ^=, xor)
0093
0094 #define arch_atomic_andnot arch_atomic_andnot
0095 #define arch_atomic_fetch_andnot arch_atomic_fetch_andnot
0096
0097 #undef ATOMIC_OPS
0098 #undef ATOMIC_FETCH_OP
0099 #undef ATOMIC_OP_RETURN
0100 #undef ATOMIC_OP
0101
0102 #endif