X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fresource.h;h=74de3607c0727a303a0fda01b26e729935711bac;hb=f17e4350dcf0c033891e52b30b0c32a4a4fed5e0;hp=d2a415c3fca9de02e181057388f2db60abce5dd1;hpb=a594d6320ee28c15332b4c0f240caab7ea8f857a;p=libucw.git diff --git a/ucw/resource.h b/ucw/resource.h index d2a415c3..74de3607 100644 --- a/ucw/resource.h +++ b/ucw/resource.h @@ -10,8 +10,8 @@ #ifndef _UCW_RESPOOL_H #define _UCW_RESPOOL_H -#include "ucw/clists.h" -#include "ucw/threads.h" +#include +#include /** * A resource pool. It contains a name of the pool (which is printed @@ -43,6 +43,7 @@ struct resource { /** Resource flags **/ enum resource_flags { RES_FLAG_TEMP = 1, // Resource is temporary + RES_FLAG_XFREE = 2, // Resource structure needs to be deallocated by xfree() }; /** @@ -130,6 +131,23 @@ struct res_class { uns res_size; // Size of the resource structure (0=default) }; +/** + * Initialize a pre-allocated buffer to the specific class of resource, setting its private data to @priv. + * This resource can be added to the current pool by @res_add(). + **/ +static inline struct resource *res_init(struct resource *r, const struct res_class *rc, void *priv) +{ + r->flags = 0; + r->rclass = rc; + r->priv = priv; + return r; +} + +/** + * Links a pre-initialized resource to the active pool. + **/ +void res_add(struct resource *r); + /** * 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