Nucleus
Barry Multitasking support db9a0c1 (3 years, 3 months ago)
/*
* This is the Object Manager. It implements the basic operations each object
* needs and leaves the rest up to the respective subsystem that implements that
* object. The object manager is a resource manager which should help improve
* memory safety within the kernel. It reference counts each object and
* controls their instantiation and deletion.
*/
#include <nucleus/object.h>
/* Obtain a reference to an object */
void *
get(void *addr)
{
Object *obj = addr;
obj->type->usage++;
obj->usage++;
return addr;
}
/* Release a reference to an object */
void
put(void *addr)
{
Object *obj = addr;
obj->type->usage--;
if (--obj->usage)
return;
obj->type->count--;
obj->type->delete(obj);
}
/* Create a new instance of an object */
void *
new(ObjectType *type)
{
Object *obj = type->new();
obj->type = type;
type->count++;
return get(obj);
}