]> mj.ucw.cz Git - libucw.git/commitdiff
Added res_detach().
authorMartin Mares <mj@ucw.cz>
Tue, 2 Sep 2008 21:17:33 +0000 (23:17 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 29 Mar 2011 10:55:05 +0000 (12:55 +0200)
ucw/respool.c
ucw/respool.h

index d596a7ae3c2c61f8ef4f7693a683c68880a1b363..6a1687f3d51a96106ca6efe4feed0c1cf5427252 100644 (file)
@@ -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
index 39f310c121e2c3ee545697dcde8b86358a8958e4..0c3449cd2c3f9ad8894aca17f6ce872c7ef067c8 100644 (file)
@@ -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 *