+/**
+ * Unlinks a resource from a pool and releases its meta-data. However, the resource itself is kept.
+ * When called with a NULL pointer, it does nothing, but safely.
+ **/
+void res_detach(struct resource *r);
+
+/** Marks a resource as temporary (sets @RES_FLAG_TEMP). **/
+static inline void res_temporary(struct resource *r)
+{
+ r->flags |= RES_FLAG_TEMP;
+}
+
+/** Marks a resource as permanent (clears @RES_FLAG_TEMP). **/
+static inline void res_permanent(struct resource *r)
+{
+ r->flags &= RES_FLAG_TEMP;
+}
+
+/***
+ * === Resource classes
+ *
+ * A resource class describes how to handle a particular type of resources.
+ * Most importantly, it defines a set of (optional) callbacks for performing operations
+ * on the resources:
+ *
+ * * dump() should print a description of the resource used for debugging
+ * to the standard output. The description should end with a newline character
+ * and in case of a multi-line description, the subsequent lines should be
+ * indented by @indent spaces.
+ * * free() frees the resource; the struct resource is freed automatically afterwards.
+ * * detach() breaks the link between the struct resource and the real resource;
+ * the struct resource is freed automatically afterwards, while the resource
+ * continues to live.
+ *
+ * The following functions are intended for use by the resource classes only.
+ ***/
+
+/** The structure describing a resource class. **/
+struct res_class {
+ const char *name; // The name of the class (included in debugging dumps)
+ void (*detach)(struct resource *r); // The callbacks
+ void (*free)(struct resource *r);
+ void (*dump)(struct resource *r, uns indent);
+ uns res_size; // Size of the resource structure (0=default)
+};
+
+/**
+ * Unlinks a resource from a pool and releases its meta-data. Unlike @res_detach(),
+ * it does not invoke any callbacks. The caller must make sure that no references to
+ * the meta-data remain, so this is generally safe only inside resource class code.
+ **/
+void res_drop(struct resource *r);
+
+/**
+ * Creates a new resource of the specific class, setting its private data to @priv.
+ * Returns NULL if there is no resource pool active.
+ **/
+static inline struct resource *res_new(const struct res_class *rc, void *priv)