From 6e307487299ee10bfc3753821601cab969592627 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 19 Apr 2011 15:42:58 +0200 Subject: [PATCH] Resources: Added eltpool class --- ucw/Makefile | 2 +- ucw/doc/trans.txt | 2 -- ucw/res-eltpool.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ ucw/respool.h | 5 ++++- 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 ucw/res-eltpool.c 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 -- 2.39.5