2 * Copyright (c) 2000-2001, 2003 Proofpoint, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 * $Id: rpool.h,v 1.17 2013-11-22 20:51:31 ca Exp $
13 ** libsm resource pools
14 ** See libsm/rpool.html for documentation.
22 # include <sm/string.h>
25 ** Each memory pool object consists of an SM_POOLLINK_T,
26 ** followed by a platform specific amount of padding,
27 ** followed by 'poolsize' bytes of pool data,
28 ** where 'poolsize' is the value of rpool->sm_poolsize at the time
29 ** the pool is allocated.
32 typedef struct sm_poollink SM_POOLLINK_T;
35 SM_POOLLINK_T *sm_pnext;
38 typedef void (*SM_RPOOL_RFREE_T) __P((void *_rcontext));
40 typedef SM_RPOOL_RFREE_T *SM_RPOOL_ATTACH_T;
42 typedef struct sm_resource SM_RESOURCE_T;
46 ** Function for freeing this resource. It may be NULL,
47 ** meaning that this resource has already been freed.
50 SM_RPOOL_RFREE_T sm_rfree;
51 void *sm_rcontext; /* resource data */
54 # define SM_RLIST_MAX 511
56 typedef struct sm_rlist SM_RLIST_T;
59 SM_RESOURCE_T sm_rvec[SM_RLIST_MAX];
65 /* Points to SmRpoolMagic, or is NULL if rpool is freed. */
69 ** If this rpool object has no parent, then sm_parentlink
70 ** is NULL. Otherwise, we set *sm_parentlink = NULL
71 ** when this rpool is freed, so that it isn't freed a
72 ** second time when the parent is freed.
75 SM_RPOOL_RFREE_T *sm_parentlink;
81 /* Size of the next pool to be allocated, not including the header. */
85 ** If an sm_rpool_malloc_x request is too big to fit
86 ** in the current pool, and the request size > bigobjectsize,
87 ** then the object will be given its own malloc'ed block.
88 ** sm_bigobjectsize <= sm_poolsize. The maximum wasted space
89 ** at the end of a pool is maxpooledobjectsize - 1.
92 size_t sm_bigobjectsize;
94 /* Points to next free byte in the current pool. */
98 ** Number of bytes available in the current pool.
99 ** Initially 0. Set to 0 by sm_rpool_free.
104 /* Linked list of memory pools. Initially NULL. */
105 SM_POOLLINK_T *sm_pools;
111 SM_RESOURCE_T *sm_rptr; /* Points to next free resource slot. */
114 ** Number of available resource slots in current list.
115 ** Initially 0. Set to 0 by sm_rpool_free.
120 /* Linked list of resource lists. Initially NULL. */
121 SM_RLIST_T *sm_rlists;
126 #endif /* _FFR_PERF_RPOOL */
132 SM_RPOOL_T *_parent));
136 SM_RPOOL_T *_rpool));
140 sm_rpool_malloc_tagged_x __P((
146 # define sm_rpool_malloc_x(rpool, size) \
147 sm_rpool_malloc_tagged_x(rpool, size, __FILE__, __LINE__, SmHeapGroup)
149 sm_rpool_malloc_tagged __P((
155 # define sm_rpool_malloc(rpool, size) \
156 sm_rpool_malloc_tagged(rpool, size, __FILE__, __LINE__, SmHeapGroup)
157 # else /* SM_HEAP_CHECK */
159 sm_rpool_malloc_x __P((
163 sm_rpool_malloc __P((
166 # endif /* SM_HEAP_CHECK */
168 #if DO_NOT_USE_STRCPY
169 extern char *sm_rpool_strdup_x __P((SM_RPOOL_T *rpool, const char *s));
170 #else /* DO_NOT_USE_STRCPY */
171 # define sm_rpool_strdup_x(rpool, str) \
172 strcpy(sm_rpool_malloc_x(rpool, strlen(str) + 1), str)
173 #endif /* DO_NOT_USE_STRCPY */
175 extern SM_RPOOL_ATTACH_T
176 sm_rpool_attach_x __P((
178 SM_RPOOL_RFREE_T _rfree,
181 # define sm_rpool_detach(a) ((void)(*(a) = NULL))
184 sm_rpool_setsizes __P((
187 size_t _bigobjectsize));
189 #endif /* ! SM_RPOOL_H */