X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Frespool.c;h=a4978fdf51ad030ff323cd00aa2b3336acd9d951;hb=623185a65b8870abb82cd0dd8547a1aa4fc1f535;hp=31cfc58a8272cb4bb88eb6fc6d7793a30d6e88ad;hpb=c41d616c80443a7755eab3e9135ae618427e5407;p=libucw.git diff --git a/ucw/respool.c b/ucw/respool.c index 31cfc58a..a4978fdf 100644 --- a/ucw/respool.c +++ b/ucw/respool.c @@ -1,7 +1,7 @@ /* * The UCW Library -- Resource Pools * - * (c) 2008 Martin Mares + * (c) 2008--2011 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -27,6 +27,7 @@ rp_new(const char *name, struct mempool *mp) rp = xmalloc_zero(sizeof(*rp)); clist_init(&rp->resources); rp->name = name; + rp->default_res_flags = RES_FLAG_TEMP; return rp; } @@ -65,6 +66,21 @@ rp_detach(struct respool *rp) rp_free(rp); } +void +rp_commit(struct respool *rp) +{ + struct resource *r; + while (r = clist_head(&rp->resources)) + { + ASSERT(r->rpool == rp); + if (r->flags & RES_FLAG_TEMP) + res_free(r); + else + res_detach(r); + } + rp_free(rp); +} + void rp_dump(struct respool *rp, uns indent) { @@ -90,6 +106,7 @@ res_alloc(const struct res_class *rc) struct resource *r = (rp->mpool ? mp_alloc_fast(rp->mpool, size) : xmalloc(size)); r->rpool = rp; clist_add_tail(&rp->resources, &r->n); + r->flags = rp->default_res_flags; return r; } @@ -120,7 +137,7 @@ res_free(struct resource *r) void res_dump(struct resource *r, uns indent) { - printf("%*s%p %s", indent, "", r, r->rclass->name); + printf("%*s%p %s %s", indent, "", r, ((r->flags & RES_FLAG_TEMP) ? "TEMP" : "PERM"), r->rclass->name); if (r->rclass->dump) r->rclass->dump(r, indent+4); else