From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
NeilBrown <neilb@suse.com>, Thomas Graf <tgraf@suug.ch>,
Herbert Xu <herbert@gondor.apana.org.au>,
Tom Herbert <tom@quantonium.net>,
Andreas Gruenbacher <agruenba@redhat.com>
Subject: [PATCH v2 1/2] lockref: Add lockref_put_not_zero
Date: Thu, 29 Mar 2018 14:06:11 +0200 [thread overview]
Message-ID: <20180329120612.6104-2-agruenba@redhat.com> (raw)
In-Reply-To: <20180329120612.6104-1-agruenba@redhat.com>
Put a lockref unless the lockref is dead or its count would become zero.
This is the same as lockref_put_or_lock except that the lock is never
left held.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
include/linux/lockref.h | 1 +
lib/lockref.c | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/linux/lockref.h b/include/linux/lockref.h
index 2eac32095113..99f17cc8e163 100644
--- a/include/linux/lockref.h
+++ b/include/linux/lockref.h
@@ -37,6 +37,7 @@ struct lockref {
extern void lockref_get(struct lockref *);
extern int lockref_put_return(struct lockref *);
extern int lockref_get_not_zero(struct lockref *);
+extern int lockref_put_not_zero(struct lockref *);
extern int lockref_get_or_lock(struct lockref *);
extern int lockref_put_or_lock(struct lockref *);
diff --git a/lib/lockref.c b/lib/lockref.c
index 47169ed7e964..3d468b53d4c9 100644
--- a/lib/lockref.c
+++ b/lib/lockref.c
@@ -80,6 +80,34 @@ int lockref_get_not_zero(struct lockref *lockref)
}
EXPORT_SYMBOL(lockref_get_not_zero);
+/**
+ * lockref_put_not_zero - Decrements count unless count <= 1 before decrement
+ * @lockref: pointer to lockref structure
+ * Return: 1 if count updated successfully or 0 if count would become zero
+ */
+int lockref_put_not_zero(struct lockref *lockref)
+{
+ int retval;
+
+ CMPXCHG_LOOP(
+ new.count--;
+ if (old.count <= 1)
+ return 0;
+ ,
+ return 1;
+ );
+
+ spin_lock(&lockref->lock);
+ retval = 0;
+ if (lockref->count > 1) {
+ lockref->count--;
+ retval = 1;
+ }
+ spin_unlock(&lockref->lock);
+ return retval;
+}
+EXPORT_SYMBOL(lockref_put_not_zero);
+
/**
* lockref_get_or_lock - Increments count unless the count is 0 or dead
* @lockref: pointer to lockref structure
--
2.14.3
next prev parent reply other threads:[~2018-03-29 12:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-29 12:06 [PATCH v2 0/2] gfs2: Stop using rhashtable_walk_peek Andreas Gruenbacher
2018-03-29 12:06 ` Andreas Gruenbacher [this message]
2018-03-29 12:06 ` [PATCH v2 2/2] " Andreas Gruenbacher
2018-03-29 12:24 ` [Cluster-devel] [PATCH v2 0/2] " Steven Whitehouse
2018-03-29 13:12 ` Andreas Gruenbacher
2018-03-29 12:35 ` Herbert Xu
2018-03-29 13:15 ` Andreas Gruenbacher
2018-03-29 15:41 ` Herbert Xu
2018-03-29 16:52 ` Andreas Gruenbacher
2018-03-29 17:06 ` Herbert Xu
2018-04-03 3:41 ` NeilBrown
2018-04-03 4:03 ` Herbert Xu
2018-04-04 15:46 ` [Cluster-devel] " Bob Peterson
2018-04-04 15:48 ` Herbert Xu
[not found] ` <CAHpGcMKxDNOkMMKB1_9H0ob-502cD89E-94a18prp91y_a52GA@mail.gmail.com>
2018-04-06 1:33 ` NeilBrown
2018-04-12 17:00 ` Bob Peterson
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=20180329120612.6104-2-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=cluster-devel@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@suse.com \
--cc=netdev@vger.kernel.org \
--cc=tgraf@suug.ch \
--cc=tom@quantonium.net \
/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;
as well as URLs for NNTP newsgroup(s).