Nucleus
Barry Basic object manager 5201ba5 (3 years, 3 months ago)
diff --git a/object/manager.c b/object/manager.c
new file mode 100644
index 0000000..a0b0c8b
--- /dev/null
+++ b/object/manager.c
@@ -0,0 +1,41 @@
+/*
+ * 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);
+}