From: Martin Mares Date: Tue, 2 Sep 2008 21:17:33 +0000 (+0200) Subject: Added res_detach(). X-Git-Tag: v5.0~74^2~39 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=91a793242b091bb158d9272f415dcb1b81740e33;p=libucw.git Added res_detach(). --- diff --git a/ucw/respool.c b/ucw/respool.c index d596a7ae..6a1687f3 100644 --- a/ucw/respool.c +++ b/ucw/respool.c @@ -30,6 +30,15 @@ rp_new(const char *name, struct mempool *mp) return rp; } +static void +rp_free(struct respool *rp) +{ + if (!rp->mpool) + xfree(rp); + if (rp_current() == rp) + rp_switch(NULL); +} + void rp_delete(struct respool *rp) { @@ -39,10 +48,19 @@ rp_delete(struct respool *rp) ASSERT(r->rpool == rp); res_free(r); } - if (!rp->mpool) - xfree(rp); - if (rp_current() == rp) - rp_switch(NULL); + rp_free(rp); +} + +void +rp_detach(struct respool *rp) +{ + struct resource *r; + while (r = clist_head(&rp->resources)) + { + ASSERT(r->rpool == rp); + res_detach(r); + } + rp_free(rp); } void diff --git a/ucw/respool.h b/ucw/respool.h index 39f310c1..0c3449cd 100644 --- a/ucw/respool.h +++ b/ucw/respool.h @@ -12,6 +12,7 @@ * - check other candidates for resourcification * - respool as a resource in another respool? * - unit tests + * - automatic freeing of trans pool on thread exit */ #ifndef _UCW_RESPOOL_H @@ -43,6 +44,7 @@ struct res_class { struct respool *rp_new(const char *name, struct mempool *mp); void rp_delete(struct respool *rp); +void rp_detach(struct respool *rp); void rp_dump(struct respool *rp); static inline struct respool *