From 91a793242b091bb158d9272f415dcb1b81740e33 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 2 Sep 2008 23:17:33 +0200 Subject: [PATCH] Added res_detach(). --- ucw/respool.c | 26 ++++++++++++++++++++++---- ucw/respool.h | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) 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 * -- 2.39.2