Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1481801

RE: [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive

From "Luck, Tony" <tony.luck@intel.com>
Newsgroups linux.kernel
Subject RE: [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive
Date 2016-09-12 20:30 +0200
Message-ID <sgE9r-6Zj-31@gated-at.bofh.it> (permalink)
References <sgDwJ-6qC-13@gated-at.bofh.it> <sgDwK-6qC-39@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


+static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
+{
+	long c, old, dec;
+	c = atomic64_read(v);
+	for (;;) {
+		dec = c - 1;
+		if (unlikely(dec < 0))
+			break;
+		old = atomic64_cmpxchg((v), c, dec);
+		if (likely(old == c))
+			break;
+		c = old;
+	}
+	return dec;
+}

I was about to say "add a cpu_relax()" in the bottom of that loop. But none of the other
atomic ops that spin on a cmpxchg do that ... so:

Acked-by: Tony Luck <tony.luck@intel.com>

-Tony

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/2] Getting rid of CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-09-12 19:50 +0200
  [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-09-12 19:50 +0200
    RE: [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive "Luck, Tony" <tony.luck@intel.com> - 2016-09-12 20:30 +0200

csiph-web