Skip to content

Commit

Permalink
kref: add kref_set()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Evgeniy Polyakov authored and gregkh committed Jan 25, 2008
1 parent 775b64d commit 41ca28a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/linux/kref.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct kref {
atomic_t refcount;
};

void kref_set(struct kref *kref, int num);
void kref_init(struct kref *kref);
void kref_get(struct kref *kref);
int kref_put(struct kref *kref, void (*release) (struct kref *kref));
Expand Down
15 changes: 13 additions & 2 deletions lib/kref.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@
#include <linux/kref.h>
#include <linux/module.h>

/**
* kref_set - initialize object and set refcount to requested number.
* @kref: object in question.
* @num: initial reference counter
*/
void kref_set(struct kref *kref, int num)
{
atomic_set(&kref->refcount, num);
smp_mb();
}

/**
* kref_init - initialize object.
* @kref: object in question.
*/
void kref_init(struct kref *kref)
{
atomic_set(&kref->refcount,1);
smp_mb();
kref_set(kref, 1);
}

/**
Expand Down Expand Up @@ -61,6 +71,7 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref))
return 0;
}

EXPORT_SYMBOL(kref_set);
EXPORT_SYMBOL(kref_init);
EXPORT_SYMBOL(kref_get);
EXPORT_SYMBOL(kref_put);

0 comments on commit 41ca28a

Please sign in to comment.