From: Alexander Aring <aahringo@redhat.com>
To: will@kernel.org
Cc: gfs2@lists.linux.dev, aahringo@redhat.com, peterz@infradead.org,
boqun.feng@gmail.com, mark.rutland@arm.com
Subject: [RFC 2/2] kref: introduce kref_put_lockptr() and use lockptr
Date: Fri, 3 Nov 2023 12:06:51 -0400 [thread overview]
Message-ID: <20231103160651.1902460-2-aahringo@redhat.com> (raw)
In-Reply-To: <20231103160651.1902460-1-aahringo@redhat.com>
This patch switches to make kref_put_lock() more locktype independend by
introducing kref_put_lockptr() and using refcount_dec_and_lockptr(). The
user can now pass a lockptr and do the specific locktype operation by
parameters. The current kref_put_mutex() and kref_put_lock() has been
adapted to use the new kref_put_lockptr() implementation for existing
users.
Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
include/linux/kref.h | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/include/linux/kref.h b/include/linux/kref.h
index d32e21a2538c..09bc79435dbb 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -68,26 +68,33 @@ static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref)
return 0;
}
-static inline int kref_put_mutex(struct kref *kref,
- void (*release)(struct kref *kref),
- struct mutex *lock)
+static inline int kref_put_lockptr(struct kref *kref,
+ void (*release)(struct kref *kref),
+ void (*lock)(void *lockptr),
+ void (*unlock)(void *lockptr),
+ void *lockptr)
{
- if (refcount_dec_and_mutex_lock(&kref->refcount, lock)) {
+ if (refcount_dec_and_lockptr(&kref->refcount, lock, unlock, lockptr)) {
release(kref);
return 1;
}
return 0;
}
+static inline int kref_put_mutex(struct kref *kref,
+ void (*release)(struct kref *kref),
+ struct mutex *lock)
+{
+ return kref_put_lockptr(kref, release, lockptr_mutex_lock,
+ lockptr_mutex_unlock, lock);
+}
+
static inline int kref_put_lock(struct kref *kref,
void (*release)(struct kref *kref),
spinlock_t *lock)
{
- if (refcount_dec_and_lock(&kref->refcount, lock)) {
- release(kref);
- return 1;
- }
- return 0;
+ return kref_put_lockptr(kref, release, lockptr_spin_lock,
+ lockptr_spin_unlock, lock);
}
/**
--
2.39.3
next prev parent reply other threads:[~2023-11-03 16:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 16:06 [RFC 1/2] refcount: introduce generic lockptr funcs Alexander Aring
2023-11-03 16:06 ` Alexander Aring [this message]
2023-11-03 16:14 ` Alexander Aring
2023-11-03 16:16 ` Alexander Aring
-- strict thread matches above, loose matches on Subject: below --
2023-11-03 16:16 Alexander Aring
2023-11-03 16:16 ` [RFC 2/2] kref: introduce kref_put_lockptr() and use lockptr Alexander Aring
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=20231103160651.1902460-2-aahringo@redhat.com \
--to=aahringo@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=gfs2@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).