mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-12-14 10:57:08 +03:00
96aa59bb73
git-svn-id: svn://kolibrios.org@2966 a494cfbc-eb01-0410-851d-a64ba20cac60
39 lines
699 B
C
39 lines
699 B
C
#include <linux/kref.h>
|
|
#include <asm/atomic.h>
|
|
|
|
|
|
void kref_set(struct kref *kref, int num)
|
|
{
|
|
atomic_set(&kref->refcount, num);
|
|
}
|
|
|
|
/**
|
|
* kref_init - initialize object.
|
|
* @kref: object in question.
|
|
*/
|
|
void kref_init(struct kref *kref)
|
|
{
|
|
kref_set(kref, 1);
|
|
}
|
|
|
|
void kref_get(struct kref *kref)
|
|
{
|
|
// WARN_ON(!atomic_read(&kref->refcount));
|
|
atomic_inc(&kref->refcount);
|
|
}
|
|
|
|
|
|
int kref_put(struct kref *kref, void (*release)(struct kref *kref))
|
|
{
|
|
// WARN_ON(release == NULL);
|
|
// WARN_ON(release == (void (*)(struct kref *))kfree);
|
|
|
|
if (atomic_dec_and_test(&kref->refcount)) {
|
|
release(kref);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|