2 * kref.c - library routines for handling generic reference counted objects
4 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2004 IBM Corp.
7 * based on lib/kobject.c which was:
8 * Copyright (C) 2002-2003 Patrick Mochel <mochel@osdl.org>
10 * This file is released under the GPLv2.
14 //#include "<kernelcompat.h>"
16 //ust// #include <linux/module.h>
21 * kref_set - initialize object and set refcount to requested number.
22 * @kref: object in question.
23 * @num: initial reference counter
25 void kref_set(struct kref
*kref
, int num
)
27 atomic_set(&kref
->refcount
, num
);
32 * kref_init - initialize object.
33 * @kref: object in question.
35 void kref_init(struct kref
*kref
)
41 * kref_get - increment refcount for object.
44 void kref_get(struct kref
*kref
)
46 WARN_ON(!atomic_read(&kref
->refcount
));
47 atomic_inc(&kref
->refcount
);
48 smp_mb__after_atomic_inc();
52 * kref_put - decrement refcount for object.
54 * @release: pointer to the function that will clean up the object when the
55 * last reference to the object is released.
56 * This pointer is required, and it is not acceptable to pass kfree
57 * in as this function.
59 * Decrement the refcount, and if 0, call release().
60 * Return 1 if the object was removed, otherwise return 0. Beware, if this
61 * function returns 0, you still can not count on the kref from remaining in
62 * memory. Only use the return value if you want to see if the kref is now
65 int kref_put(struct kref
*kref
, void (*release
)(struct kref
*kref
))
67 WARN_ON(release
== NULL
);
68 //ust// WARN_ON(release == (void (*)(struct kref *))kfree);
70 if (atomic_dec_and_test(&kref
->refcount
)) {
77 //ust// EXPORT_SYMBOL(kref_set);
78 //ust// EXPORT_SYMBOL(kref_init);
79 //ust// EXPORT_SYMBOL(kref_get);
80 //ust// EXPORT_SYMBOL(kref_put);
This page took 0.035317 seconds and 4 git commands to generate.