update ddk

git-svn-id: svn://kolibrios.org@2966 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge)
2012-09-04 21:40:09 +00:00
parent 4d9c0c2526
commit 96aa59bb73
4 changed files with 115 additions and 52 deletions

38
drivers/ddk/linux/kref.c Normal file
View File

@@ -0,0 +1,38 @@
#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;
}