2 * The UCW Library -- Resource Pools
4 * (c) 2008 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "ucw/respool.h"
12 #include "ucw/mempool.h"
17 rp_new(const char *name, struct mempool *mp)
23 rp = mp_alloc_zero(mp, sizeof(*rp));
27 rp = xmalloc_zero(sizeof(*rp));
28 clist_init(&rp->resources);
34 rp_delete(struct respool *rp)
37 while (r = clist_tail(&rp->resources))
44 rp_dump(struct respool *rp)
46 printf("Resource pool %s at %p (%s):\n", (rp->name ? : "(noname)"), rp, (rp->mpool ? "mempool-based" : "freestanding"));
47 CLIST_FOR_EACH(struct resource *, r, rp->resources)
54 struct respool *rp = rp_current();
58 struct resource *r = (rp->mpool ? mp_alloc_fast(rp->mpool, sizeof(*r)) : xmalloc(sizeof(*r)));
59 clist_add_tail(&rp->resources, &r->n);
64 res_do_free(struct resource *r)
72 res_detach(struct resource *r)
74 if (r->rclass->detach)
80 res_free(struct resource *r)
88 res_dump(struct resource *r)
90 printf("\t%p %s", r, r->rclass->name);
100 struct respool *rp = rp_new("test", NULL);