From: Oleg Nesterov <oleg@tv-sign.ru>
To: "David S. Miller" <davem@davemloft.net>,
David Howells <dhowells@redhat.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
"Paul E. McKenney" <paulmck@us.ibm.com>,
linux-kernel@vger.kernel.org
Subject: atomic_add_unless() and mb()
Date: Sun, 26 Nov 2006 00:18:18 +0300 [thread overview]
Message-ID: <20061125211818.GA167@oleg> (raw)
Both Documentation/memory-barriers.txt and Documentation/atomic_ops.txt state
that atomic_add_unless() implies smp_mb() on each side of the operation.
Is it true?
include/asm-most_of/atomic.h:
#define atomic_add_unless(v, a, u) \
({ \
int c, old; \
c = atomic_read(v); \
for (;;) { \
if (unlikely(c == (u))) \
break; \
old = atomic_cmpxchg((v), c, c + (a)); \
if (likely(old == c)) \
break; \
c = old; \
} \
c != (u); \
})
This looks like atomic_add_unless() implies mb() only if it returns 1.
Otherwise it could fail (return 0) before the first atomic_cmpxchg(),
but atomic_read() provides a compiler barrier only.
Could you clarify?
Oleg.
reply other threads:[~2006-11-25 21:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061125211818.GA167@oleg \
--to=oleg@tv-sign.ru \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@us.ibm.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox