0001
0002 #ifndef _TOOLS_LINUX_ASM_X86_ATOMIC_H
0003 #define _TOOLS_LINUX_ASM_X86_ATOMIC_H
0004
0005 #include <linux/compiler.h>
0006 #include <linux/types.h>
0007 #include "rmwcc.h"
0008
0009 #define LOCK_PREFIX "\n\tlock; "
0010
0011 #include <asm/cmpxchg.h>
0012
0013
0014
0015
0016
0017
0018 #define ATOMIC_INIT(i) { (i) }
0019
0020
0021
0022
0023
0024
0025
0026 static inline int atomic_read(const atomic_t *v)
0027 {
0028 return READ_ONCE((v)->counter);
0029 }
0030
0031
0032
0033
0034
0035
0036
0037
0038 static inline void atomic_set(atomic_t *v, int i)
0039 {
0040 v->counter = i;
0041 }
0042
0043
0044
0045
0046
0047
0048
0049 static inline void atomic_inc(atomic_t *v)
0050 {
0051 asm volatile(LOCK_PREFIX "incl %0"
0052 : "+m" (v->counter));
0053 }
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 static inline int atomic_dec_and_test(atomic_t *v)
0064 {
0065 GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
0066 }
0067
0068 static __always_inline int atomic_cmpxchg(atomic_t *v, int old, int new)
0069 {
0070 return cmpxchg(&v->counter, old, new);
0071 }
0072
0073 #endif