From: Arun Sharma <asharma@fb.com>
To: linux-kernel@vger.kernel.org
Cc: Arun Sharma <asharma@fb.com>, Ingo Molnar <mingo@elte.hu>,
David Miller <davem@davemloft.net>, Andrew Morton <akpm@osdl.org>,
Eric Dumazet <eric.dumazet@gmail.com>,
Mike Frysinger <vapier.adi@gmail.com>
Subject: [PATCH 3/3] atomic: generalize atomic_add_unless_return
Date: Mon, 6 Jun 2011 10:27:31 -0700 [thread overview]
Message-ID: <1307381251-15729-3-git-send-email-asharma@fb.com> (raw)
In-Reply-To: <1307381251-15729-1-git-send-email-asharma@fb.com>
commit 686a7e3 added atomic_add_unless_return() to get something going
for the stable branch.
Move the primitive to <linux/atomic.h>
Signed-off-by: Arun Sharma <asharma@fb.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David Miller <davem@davemloft.net>
Cc: Andrew Morton <akpm@osdl.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Mike Frysinger <vapier.adi@gmail.com>
LKML-Reference: <20110531105019.GF24172@elte.hu>
---
include/linux/atomic.h | 15 +++++++++++++++
net/ipv4/inetpeer.c | 17 ++---------------
2 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/include/linux/atomic.h b/include/linux/atomic.h
index fc31190..3489d9c 100644
--- a/include/linux/atomic.h
+++ b/include/linux/atomic.h
@@ -17,6 +17,21 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
}
/**
+ * atomic_add_unless_return - add unless the number is already a given value
+ * @v: pointer of type atomic_t
+ * @a: the amount to add to v...
+ * @u: ...unless v is equal to u.
+ *
+ * Atomically adds @a to @v, so long as @v was not already @u.
+ * Returns the desired new value of @v (old value of @v + @a)
+ * (Note: return value of @u + @a indicates that the add failed)
+ */
+static inline int atomic_add_unless_return(atomic_t *v, int a, int u)
+{
+ return __atomic_add_unless(v, a, u) + a;
+}
+
+/**
* atomic_inc_not_zero - increment unless the number is zero
* @v: pointer of type atomic_t
*
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index ce616d9..d4190ae 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -203,20 +203,6 @@ static int addr_compare(const struct inetpeer_addr *a,
u; \
})
-static bool atomic_add_unless_return(atomic_t *ptr, int a, int u, int *newv)
-{
- int cur, old = atomic_read(ptr);
-
- while (old != u) {
- *newv = old + a;
- cur = atomic_cmpxchg(ptr, old, *newv);
- if (cur == old)
- return true;
- old = cur;
- }
- return false;
-}
-
/*
* Called with rcu_read_lock()
* Because we hold no lock against a writer, its quite possible we fall
@@ -239,7 +225,8 @@ static struct inet_peer *lookup_rcu(const struct inetpeer_addr *daddr,
* distinction between an unused entry (refcnt=0) and
* a freed one.
*/
- if (!atomic_add_unless_return(&u->refcnt, 1, -1, newrefcnt))
+ *newrefcnt = atomic_add_unless_return(&u->refcnt, 1, -1);
+ if (*newrefcnt == 0)
u = NULL;
return u;
}
--
1.7.4
next prev parent reply other threads:[~2011-06-06 17:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-06 17:27 [PATCH 1/3] atomic: use <linux/atomic.h> Arun Sharma
2011-06-06 17:27 ` [PATCH 2/3] atomic: move atomic_add_unless to generic code Arun Sharma
2011-06-06 20:56 ` Eric Dumazet
2011-06-06 17:27 ` Arun Sharma [this message]
2011-06-06 20:58 ` [PATCH 3/3] atomic: generalize atomic_add_unless_return Eric Dumazet
2011-06-09 18:01 ` Eric Dumazet
2011-06-06 20:55 ` [PATCH 1/3] atomic: use <linux/atomic.h> Eric Dumazet
2011-06-06 21:06 ` Arun Sharma
2011-06-15 23:31 ` Andrew Morton
2011-06-16 0:57 ` Arun Sharma
2011-06-16 1:29 ` [PATCH] atomic: cleanup asm-generic atomic*.h inclusion Arun Sharma
2011-06-17 6:36 ` Mike Frysinger
2011-06-17 17:11 ` Arun Sharma
2011-06-17 17:28 ` Mike Frysinger
2011-06-17 17:49 ` Arun Sharma
2011-06-17 18:06 ` Mike Frysinger
2011-06-17 18:42 ` Arun Sharma
2011-06-17 19:07 ` Mike Frysinger
2011-06-17 20:05 ` Arun Sharma
2011-06-08 0:07 [PATCH 1/3] atomic: use <linux/atomic.h> Arun Sharma
2011-06-08 0:07 ` [PATCH 3/3] atomic: generalize atomic_add_unless_return Arun Sharma
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=1307381251-15729-3-git-send-email-asharma@fb.com \
--to=asharma@fb.com \
--cc=akpm@osdl.org \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=vapier.adi@gmail.com \
/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
all inboxes | Powered by JetHome®