/* * 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); }