summaryrefslogtreecommitdiffstats
path: root/lib/refcount.c
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2017-02-01 16:39:38 +0100
committerIngo Molnar <mingo@kernel.org>2017-03-23 08:54:40 +0100
commita9ebf306f52c756c4f9e50ee9a60cd6389d71344 (patch)
treeb1637bcffdc85d3e6e49858a8de5de3ba4ef2f7d /lib/refcount.c
parentlocking/ww_mutex: Improve test to cover acquire context changes (diff)
downloadlinux-a9ebf306f52c756c4f9e50ee9a60cd6389d71344.tar.xz
linux-a9ebf306f52c756c4f9e50ee9a60cd6389d71344.zip
locking/atomic: Introduce atomic_try_cmpxchg()
Add a new cmpxchg interface: bool try_cmpxchg(u{8,16,32,64} *ptr, u{8,16,32,64} *val, u{8,16,32,64} new); Where the boolean returns the result of the compare; and thus if the exchange happened; and in case of failure, the new value of *ptr is returned in *val. This allows simplification/improvement of loops like: for (;;) { new = val $op $imm; old = cmpxchg(ptr, val, new); if (old == val) break; val = old; } into: do { } while (!try_cmpxchg(ptr, &val, val $op $imm)); while also generating better code (GCC6 and onwards). Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'lib/refcount.c')
0 files changed, 0 insertions, 0 deletions