Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2966 Serge 1
#include 
2
#include 
3
 
4
 
5
void kref_set(struct kref *kref, int num)
6
{
7
    atomic_set(&kref->refcount, num);
8
}
9
 
10
/**
11
 * kref_init - initialize object.
12
 * @kref: object in question.
13
 */
14
void kref_init(struct kref *kref)
15
{
16
    kref_set(kref, 1);
17
}
18
 
19
void kref_get(struct kref *kref)
20
{
21
//    WARN_ON(!atomic_read(&kref->refcount));
22
    atomic_inc(&kref->refcount);
23
}
24
 
25
 
26
int kref_put(struct kref *kref, void (*release)(struct kref *kref))
27
{
28
//    WARN_ON(release == NULL);
29
//    WARN_ON(release == (void (*)(struct kref *))kfree);
30
 
31
    if (atomic_dec_and_test(&kref->refcount)) {
32
        release(kref);
33
        return 1;
34
    }
35
    return 0;
36
}
37