VSF Documented
kref.h
Go to the documentation of this file.
1#ifndef __VSF_LINUX_KREF_H__
2#define __VSF_LINUX_KREF_H__
3
4#include <linux/refcount.h>
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10struct kref {
12};
13
14#define KREF_INIT(__N) { .refcount = REFCOUNT_INIT(__N) }
15
16static inline void kref_init(struct kref *kref)
17{
18 refcount_set(&kref->refcount, 1);
19}
20
21static inline unsigned int kref_read(const struct kref *kref)
22{
23 return refcount_read((refcount_t *)&kref->refcount);
24}
25
26static inline void kref_get(struct kref *kref)
27{
28 refcount_inc(&kref->refcount);
29}
30
31static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref))
32{
33 if (refcount_dec_and_test(&kref->refcount)) {
34 release(kref);
35 return 1;
36 }
37 return 0;
38}
39
40#ifdef __cplusplus
41}
42#endif
43
44#endif
Definition kref.h:10
refcount_t refcount
Definition kref.h:11
Definition refcount.h:11