2 * The UCW Library -- Resource Pools
4 * (c) 2008 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
10 #ifndef _UCW_RESPOOL_H
11 #define _UCW_RESPOOL_H
13 #include "ucw/clists.h"
14 #include "ucw/threads.h"
19 struct mempool *mpool; // If set, resources are allocated from the mempool, otherwise by xmalloc()
24 struct respool *rpool;
25 struct res_class *rclass;
26 void *priv; // Private to the class
31 void (*detach)(struct resource *r);
32 void (*free)(struct resource *r);
33 void (*dump)(struct resource *r);
36 struct respool *rp_new(const char *name, struct mempool *mp);
37 void rp_delete(struct respool *rp);
38 void rp_dump(struct respool *rp);
40 static inline struct respool *
43 return ucwlib_thread_context()->current_respool; // May be NULL
46 static inline struct respool *
47 rp_switch(struct respool *rp)
49 struct ucwlib_context *ctx = ucwlib_thread_context();
50 struct respool *orp = ctx->current_respool;
51 ctx->current_respool = rp;
55 struct resource *res_alloc(void); // Returns NULL if there is no pool active
56 void res_detach(struct resource *r);
57 void res_free(struct resource *r);
58 void res_dump(struct resource *r);
60 static inline struct resource * // Returns NULL if there is no pool active
61 res_new(struct res_class *rc, void *priv)
63 struct resource *r = res_alloc();