BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / 27ddc7fe7d977cb1c3a1cfff78dd1e4853bf5ad6 / object / manager.c

// Related

Nucleus

Barry Basic object manager 5201ba5 (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 "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);
}