diff options
author | Christoph Hellwig <hch@lst.de> | 2025-01-15 12:46:41 +0300 |
---|---|---|
committer | Christian Brauner <brauner@kernel.org> | 2025-01-16 13:48:11 +0300 |
commit | 63440d1c6dd1fc782db905319dbfb4db354e54b9 (patch) | |
tree | 1ac1c5d39c3cf67f3eaa7ef70421c166f744dd2f | |
parent | 25d8060418b4e83e109b20f3b3931301e254b8f4 (diff) | |
download | linux-63440d1c6dd1fc782db905319dbfb4db354e54b9.tar.xz |
lockref: add a lockref_init helper
Add a helper to initialize the lockdep, that is initialize the spinlock
and set a value. Having to open code them isn't a big deal, but having
an initializer feels right for a proper primitive.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250115094702.504610-6-hch@lst.de
Signed-off-by: Christian Brauner <brauner@kernel.org>
-rw-r--r-- | include/linux/lockref.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/lockref.h b/include/linux/lockref.h index f821f46e9fb4..c39f119659ba 100644 --- a/include/linux/lockref.h +++ b/include/linux/lockref.h @@ -34,6 +34,17 @@ struct lockref { }; }; +/** + * lockref_init - Initialize a lockref + * @lockref: pointer to lockref structure + * @count: initial count + */ +static inline void lockref_init(struct lockref *lockref, unsigned int count) +{ + spin_lock_init(&lockref->lock); + lockref->count = count; +} + void lockref_get(struct lockref *lockref); int lockref_put_return(struct lockref *lockref); bool lockref_get_not_zero(struct lockref *lockref); |