diff options
author | Evgeniy Polyakov <johnpol@2ka.mipt.ru> | 2007-12-10 15:03:43 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-01-24 23:40:05 -0500 |
commit | 41ca28ab2abd76dc203e2c3a7cd609607cb927c3 (patch) | |
tree | 9197e7582b4654796914090026e1afed2628d101 | |
parent | 775b64d2b6ca37697de925f70799c710aab5849a (diff) |
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>
-rw-r--r-- | include/linux/kref.h | 1 | ||||
-rw-r--r-- | lib/kref.c | 15 |
2 files changed, 14 insertions, 2 deletions
diff --git a/include/linux/kref.h b/include/linux/kref.h index 6fee3539893f..5d185635786e 100644 --- a/include/linux/kref.h +++ b/include/linux/kref.h | |||
@@ -24,6 +24,7 @@ struct kref { | |||
24 | atomic_t refcount; | 24 | atomic_t refcount; |
25 | }; | 25 | }; |
26 | 26 | ||
27 | void kref_set(struct kref *kref, int num); | ||
27 | void kref_init(struct kref *kref); | 28 | void kref_init(struct kref *kref); |
28 | void kref_get(struct kref *kref); | 29 | void kref_get(struct kref *kref); |
29 | int kref_put(struct kref *kref, void (*release) (struct kref *kref)); | 30 | int kref_put(struct kref *kref, void (*release) (struct kref *kref)); |
diff --git a/lib/kref.c b/lib/kref.c index a6dc3ec328e0..9ecd6e865610 100644 --- a/lib/kref.c +++ b/lib/kref.c | |||
@@ -15,13 +15,23 @@ | |||
15 | #include <linux/module.h> | 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 | * kref_init - initialize object. | 29 | * kref_init - initialize object. |
19 | * @kref: object in question. | 30 | * @kref: object in question. |
20 | */ | 31 | */ |
21 | void kref_init(struct kref *kref) | 32 | void kref_init(struct kref *kref) |
22 | { | 33 | { |
23 | atomic_set(&kref->refcount,1); | 34 | kref_set(kref, 1); |
24 | smp_mb(); | ||
25 | } | 35 | } |
26 | 36 | ||
27 | /** | 37 | /** |
@@ -61,6 +71,7 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref)) | |||
61 | return 0; | 71 | return 0; |
62 | } | 72 | } |
63 | 73 | ||
74 | EXPORT_SYMBOL(kref_set); | ||
64 | EXPORT_SYMBOL(kref_init); | 75 | EXPORT_SYMBOL(kref_init); |
65 | EXPORT_SYMBOL(kref_get); | 76 | EXPORT_SYMBOL(kref_get); |
66 | EXPORT_SYMBOL(kref_put); | 77 | EXPORT_SYMBOL(kref_put); |