Skip to content

Commit

Permalink
tools arch x86: Introduce atomic_cmpxchg()
Browse files Browse the repository at this point in the history
Will be used by atomic_cmpxchg_relaxed(), in turn used by refcount.h.

Cc: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Elena Reshetova <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Mar 3, 2017
1 parent 3337e68 commit 8a73615
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tools/arch/x86/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#define LOCK_PREFIX "\n\tlock; "

#include <asm/cmpxchg.h>

/*
* Atomic operations that C can't guarantee us. Useful for
* resource counting etc..
Expand Down Expand Up @@ -62,4 +64,9 @@ static inline int atomic_dec_and_test(atomic_t *v)
GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
}

static __always_inline int atomic_cmpxchg(atomic_t *v, int old, int new)
{
return cmpxchg(&v->counter, old, new);
}

#endif /* _TOOLS_LINUX_ASM_X86_ATOMIC_H */

0 comments on commit 8a73615

Please sign in to comment.