]> mj.ucw.cz Git - libucw.git/blob - ucw/res-mempool.c
Mapping of whole files: Converted to size_t.
[libucw.git] / ucw / res-mempool.c
1 /*
2  *      The UCW Library -- Resources for Memory Pools
3  *
4  *      (c) 2011 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include <ucw/lib.h>
11 #include <ucw/resource.h>
12 #include <ucw/mempool.h>
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17
18 static void
19 mp_res_free(struct resource *r)
20 {
21   mp_delete(r->priv);
22 }
23
24 static void
25 mp_res_dump(struct resource *r, uns indent UNUSED)
26 {
27   printf(" pool=%p\n", r->priv);
28 }
29
30 static const struct res_class mp_res_class = {
31   .name = "mempool",
32   .dump = mp_res_dump,
33   .free = mp_res_free,
34 };
35
36 struct resource *
37 res_mempool(struct mempool *mp)
38 {
39   return res_new(&mp_res_class, mp);
40 }
41
42 #ifdef TEST
43
44 int main(void)
45 {
46   struct respool *rp = rp_new("test", NULL);
47   rp_switch(rp);
48   res_mempool(mp_new(4096));
49   rp_dump(rp, 0);
50   rp_delete(rp);
51   return 0;
52 }
53
54 #endif