]> mj.ucw.cz Git - libucw.git/commitdiff
Resources: Added eltpool class
authorMartin Mares <mj@ucw.cz>
Tue, 19 Apr 2011 13:42:58 +0000 (15:42 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 19 Apr 2011 13:42:58 +0000 (15:42 +0200)
ucw/Makefile
ucw/doc/trans.txt
ucw/res-eltpool.c [new file with mode: 0644]
ucw/respool.h

index ff7707e55ec38072ae39b6c79ca78e56ef39702f..e97c28321a8c1f32d811a6b6cb5adfecadb84ba1 100644 (file)
@@ -34,7 +34,7 @@ LIBUCW_MODS= \
        bbuf gary \
        getopt \
        strtonum \
-       respool trans res-fd res-mem res-subpool res-mempool
+       respool trans res-fd res-mem res-subpool res-mempool res-eltpool
 
 LIBUCW_MAIN_INCLUDES= \
        lib.h log.h threads.h \
index 3ebf7543e964d33f79edc1f4de91ea477eea318d..152c6dad1a1430cbd6d0b995351027c3fa7d0d4c 100644 (file)
@@ -149,8 +149,6 @@ following exception types are defined:
 - Unit tests
 - Resourcification of more libucw objects:
        * bigalloc
-       * eltpool
        * gary
        * mainloop
-       * mempool
 - More exceptions
diff --git a/ucw/res-eltpool.c b/ucw/res-eltpool.c
new file mode 100644 (file)
index 0000000..b6027ae
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *     The UCW Library -- Resources for Memory Pools
+ *
+ *     (c) 2011 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
+ */
+
+#include "ucw/lib.h"
+#include "ucw/respool.h"
+#include "ucw/eltpool.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void
+ep_res_free(struct resource *r)
+{
+  ep_delete(r->priv);
+}
+
+static void
+ep_res_dump(struct resource *r, uns indent UNUSED)
+{
+  printf(" pool=%p\n", r->priv);
+}
+
+static const struct res_class ep_res_class = {
+  .name = "eltpool",
+  .dump = ep_res_dump,
+  .free = ep_res_free,
+};
+
+struct resource *
+res_eltpool(struct eltpool *mp)
+{
+  return res_new(&ep_res_class, mp);
+}
+
+#ifdef TEST
+
+int main(void)
+{
+  struct respool *rp = rp_new("test", NULL);
+  rp_switch(rp);
+  res_eltpool(ep_new(16, 256));
+  rp_dump(rp, 0);
+  rp_delete(rp);
+  return 0;
+}
+
+#endif
index 22d40a9af83e3a2493d414e418ee87d041d5d7ef..d2a415c3fca9de02e181057388f2db60abce5dd1 100644 (file)
@@ -167,6 +167,9 @@ void *res_realloc(struct resource *res, size_t size);                       /** Re-allocates memory
 struct resource *res_subpool(struct respool *rp);
 
 struct mempool;
-struct resource *res_mempool(struct mempool *mp);                      /** Creates a resource for the specified memory pool. **/
+struct resource *res_mempool(struct mempool *mp);                      /** Creates a resource for the specified <<mempool:,memory pool>>. **/
+
+struct eltpool;
+struct resource *res_eltpool(struct eltpool *ep);                      /** Creates a resource for the specified <<eltpool:,element pool>>. **/
 
 #endif