lkml.org 
[lkml]   [2021]   [Nov]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] refcount: introduce refcount_is_one() helper function
Date
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
\
 
 \ /
  Last update: 2021-11-18 04:55    [W:0.069 / U:0.588 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site