Skip to content

Commit 63440d1

Browse files
Christoph Hellwigbrauner
authored andcommitted
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>
1 parent 25d8060 commit 63440d1

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

include/linux/lockref.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ struct lockref {
3434
};
3535
};
3636

37+
/**
38+
* lockref_init - Initialize a lockref
39+
* @lockref: pointer to lockref structure
40+
* @count: initial count
41+
*/
42+
static inline void lockref_init(struct lockref *lockref, unsigned int count)
43+
{
44+
spin_lock_init(&lockref->lock);
45+
lockref->count = count;
46+
}
47+
3748
void lockref_get(struct lockref *lockref);
3849
int lockref_put_return(struct lockref *lockref);
3950
bool lockref_get_not_zero(struct lockref *lockref);

0 commit comments

Comments
 (0)