Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools arch x86: Introduce atomic_cmpxchg()

Will be used by atomic_cmpxchg_relaxed(), in turn used by refcount.h.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Elena Reshetova <elena.reshetova@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-kdmovd3l4gw5b1w31ypr6ddv@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+7
+7
tools/arch/x86/include/asm/atomic.h
··· 7 7 8 8 #define LOCK_PREFIX "\n\tlock; " 9 9 10 + #include <asm/cmpxchg.h> 11 + 10 12 /* 11 13 * Atomic operations that C can't guarantee us. Useful for 12 14 * resource counting etc.. ··· 62 60 static inline int atomic_dec_and_test(atomic_t *v) 63 61 { 64 62 GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e"); 63 + } 64 + 65 + static __always_inline int atomic_cmpxchg(atomic_t *v, int old, int new) 66 + { 67 + return cmpxchg(&v->counter, old, new); 65 68 } 66 69 67 70 #endif /* _TOOLS_LINUX_ASM_X86_ATOMIC_H */