From: Martin Mares Date: Tue, 19 Apr 2011 13:42:58 +0000 (+0200) Subject: Resources: Added eltpool class X-Git-Tag: v5.0~74^2~4 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=6e307487299ee10bfc3753821601cab969592627;p=libucw.git Resources: Added eltpool class --- diff --git a/ucw/Makefile b/ucw/Makefile index ff7707e5..e97c2832 100644 --- a/ucw/Makefile +++ b/ucw/Makefile @@ -34,7 +34,7 @@ LIBUCW_MODS= \ bbuf gary \ getopt \ strtonum \ - respool trans res-fd res-mem res-subpool res-mempool + respool trans res-fd res-mem res-subpool res-mempool res-eltpool LIBUCW_MAIN_INCLUDES= \ lib.h log.h threads.h \ diff --git a/ucw/doc/trans.txt b/ucw/doc/trans.txt index 3ebf7543..152c6dad 100644 --- a/ucw/doc/trans.txt +++ b/ucw/doc/trans.txt @@ -149,8 +149,6 @@ following exception types are defined: - Unit tests - Resourcification of more libucw objects: * bigalloc - * eltpool * gary * mainloop - * mempool - More exceptions diff --git a/ucw/res-eltpool.c b/ucw/res-eltpool.c new file mode 100644 index 00000000..b6027aed --- /dev/null +++ b/ucw/res-eltpool.c @@ -0,0 +1,54 @@ +/* + * The UCW Library -- Resources for Memory Pools + * + * (c) 2011 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. + */ + +#include "ucw/lib.h" +#include "ucw/respool.h" +#include "ucw/eltpool.h" + +#include +#include +#include + +static void +ep_res_free(struct resource *r) +{ + ep_delete(r->priv); +} + +static void +ep_res_dump(struct resource *r, uns indent UNUSED) +{ + printf(" pool=%p\n", r->priv); +} + +static const struct res_class ep_res_class = { + .name = "eltpool", + .dump = ep_res_dump, + .free = ep_res_free, +}; + +struct resource * +res_eltpool(struct eltpool *mp) +{ + return res_new(&ep_res_class, mp); +} + +#ifdef TEST + +int main(void) +{ + struct respool *rp = rp_new("test", NULL); + rp_switch(rp); + res_eltpool(ep_new(16, 256)); + rp_dump(rp, 0); + rp_delete(rp); + return 0; +} + +#endif diff --git a/ucw/respool.h b/ucw/respool.h index 22d40a9a..d2a415c3 100644 --- a/ucw/respool.h +++ b/ucw/respool.h @@ -167,6 +167,9 @@ void *res_realloc(struct resource *res, size_t size); /** Re-allocates memory struct resource *res_subpool(struct respool *rp); struct mempool; -struct resource *res_mempool(struct mempool *mp); /** Creates a resource for the specified memory pool. **/ +struct resource *res_mempool(struct mempool *mp); /** Creates a resource for the specified <>. **/ + +struct eltpool; +struct resource *res_eltpool(struct eltpool *ep); /** Creates a resource for the specified <>. **/ #endif