linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] refcount: introduce refcount_is_one() helper function
@ 2021-11-18  3:53 Yajun Deng
  2021-11-18  7:42 ` Peter Zijlstra
  2021-11-18  8:12 ` yajun.deng
  0 siblings, 2 replies; 6+ messages in thread
From: Yajun Deng @ 2021-11-18  3:53 UTC (permalink / raw)
  To: will, peterz, boqun.feng; +Cc: linux-kernel, Yajun Deng

There are many cases where it is necessary to determine if refcount is one,
introduce refcount_is_one() helper function for these cases.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 include/linux/refcount.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/linux/refcount.h b/include/linux/refcount.h
index b8a6e387f8f9..1cc23c0e7454 100644
--- a/include/linux/refcount.h
+++ b/include/linux/refcount.h
@@ -147,6 +147,11 @@ static inline unsigned int refcount_read(const refcount_t *r)
 	return atomic_read(&r->refs);
 }
 
+static inline bool refcount_is_one(const refcount_t *r)
+{
+	return refcount_read(r) == 1;
+}
+
 static inline __must_check bool __refcount_add_not_zero(int i, refcount_t *r, int *oldp)
 {
 	int old = refcount_read(r);
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-18 10:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18  3:53 [PATCH] refcount: introduce refcount_is_one() helper function Yajun Deng
2021-11-18  7:42 ` Peter Zijlstra
2021-11-18  8:12 ` yajun.deng
2021-11-18  8:44   ` Peter Zijlstra
2021-11-18 10:34   ` yajun.deng
2021-11-18 10:49     ` Peter Zijlstra

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).