[PATCH] refcount: introduce refcount_is_one() helper function

From: Yajun Deng
Date: Wed Nov 17 2021 - 22:54:06 EST


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@xxxxxxxxx>
---
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