Commit 41ca28ab2abd76dc203e2c3a7cd609607cb927c3
Committed by
Greg Kroah-Hartman
1 parent
775b64d2b6
Exists in
master
and in
4 other branches
kref: add kref_set()
This adds kref_set() to the kref api for future use by people who really know what they are doing with krefs... From: Evgeniy Polyakov <johnpol@2ka.mipt.ru> Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 2 changed files with 14 additions and 2 deletions Side-by-side Diff
include/linux/kref.h
lib/kref.c
... | ... | @@ -15,13 +15,23 @@ |
15 | 15 | #include <linux/module.h> |
16 | 16 | |
17 | 17 | /** |
18 | + * kref_set - initialize object and set refcount to requested number. | |
19 | + * @kref: object in question. | |
20 | + * @num: initial reference counter | |
21 | + */ | |
22 | +void kref_set(struct kref *kref, int num) | |
23 | +{ | |
24 | + atomic_set(&kref->refcount, num); | |
25 | + smp_mb(); | |
26 | +} | |
27 | + | |
28 | +/** | |
18 | 29 | * kref_init - initialize object. |
19 | 30 | * @kref: object in question. |
20 | 31 | */ |
21 | 32 | void kref_init(struct kref *kref) |
22 | 33 | { |
23 | - atomic_set(&kref->refcount,1); | |
24 | - smp_mb(); | |
34 | + kref_set(kref, 1); | |
25 | 35 | } |
26 | 36 | |
27 | 37 | /** |
... | ... | @@ -61,6 +71,7 @@ |
61 | 71 | return 0; |
62 | 72 | } |
63 | 73 | |
74 | +EXPORT_SYMBOL(kref_set); | |
64 | 75 | EXPORT_SYMBOL(kref_init); |
65 | 76 | EXPORT_SYMBOL(kref_get); |
66 | 77 | EXPORT_SYMBOL(kref_put); |