2 * Copyright (c) 2000-2001, 2003 Sendmail, 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.16 2003/09/05 23:07:49 ca Exp $
12 #pragma ident "%Z%%M% %I% %E% SMI"
15 ** libsm resource pools
16 ** See libsm/rpool.html for documentation.
24 # include <sm/string.h>
27 ** Each memory pool object consists of an SM_POOLLINK_T,
28 ** followed by a platform specific amount of padding,
29 ** followed by 'poolsize' bytes of pool data,
30 ** where 'poolsize' is the value of rpool->sm_poolsize at the time
31 ** the pool is allocated.
34 typedef struct sm_poollink SM_POOLLINK_T
;
37 SM_POOLLINK_T
*sm_pnext
;
40 typedef void (*SM_RPOOL_RFREE_T
) __P((void *_rcontext
));
42 typedef SM_RPOOL_RFREE_T
*SM_RPOOL_ATTACH_T
;
44 typedef struct sm_resource SM_RESOURCE_T
;
48 ** Function for freeing this resource. It may be NULL,
49 ** meaning that this resource has already been freed.
52 SM_RPOOL_RFREE_T sm_rfree
;
53 void *sm_rcontext
; /* resource data */
56 # define SM_RLIST_MAX 511
58 typedef struct sm_rlist SM_RLIST_T
;
61 SM_RESOURCE_T sm_rvec
[SM_RLIST_MAX
];
67 /* Points to SmRpoolMagic, or is NULL if rpool is freed. */
71 ** If this rpool object has no parent, then sm_parentlink
72 ** is NULL. Otherwise, we set *sm_parentlink = NULL
73 ** when this rpool is freed, so that it isn't freed a
74 ** second time when the parent is freed.
77 SM_RPOOL_RFREE_T
*sm_parentlink
;
83 /* Size of the next pool to be allocated, not including the header. */
87 ** If an sm_rpool_malloc_x request is too big to fit
88 ** in the current pool, and the request size > bigobjectsize,
89 ** then the object will be given its own malloc'ed block.
90 ** sm_bigobjectsize <= sm_poolsize. The maximum wasted space
91 ** at the end of a pool is maxpooledobjectsize - 1.
94 size_t sm_bigobjectsize
;
96 /* Points to next free byte in the current pool. */
100 ** Number of bytes available in the current pool.
101 ** Initially 0. Set to 0 by sm_rpool_free.
106 /* Linked list of memory pools. Initially NULL. */
107 SM_POOLLINK_T
*sm_pools
;
113 SM_RESOURCE_T
*sm_rptr
; /* Points to next free resource slot. */
116 ** Number of available resource slots in current list.
117 ** Initially 0. Set to 0 by sm_rpool_free.
122 /* Linked list of resource lists. Initially NULL. */
123 SM_RLIST_T
*sm_rlists
;
128 #endif /* _FFR_PERF_RPOOL */
134 SM_RPOOL_T
*_parent
));
138 SM_RPOOL_T
*_rpool
));
142 sm_rpool_malloc_tagged_x
__P((
148 # define sm_rpool_malloc_x(rpool, size) \
149 sm_rpool_malloc_tagged_x(rpool, size, __FILE__, __LINE__, SmHeapGroup)
151 sm_rpool_malloc_tagged
__P((
157 # define sm_rpool_malloc(rpool, size) \
158 sm_rpool_malloc_tagged(rpool, size, __FILE__, __LINE__, SmHeapGroup)
159 # else /* SM_HEAP_CHECK */
161 sm_rpool_malloc_x
__P((
165 sm_rpool_malloc
__P((
168 # endif /* SM_HEAP_CHECK */
170 #if DO_NOT_USE_STRCPY
171 extern char *sm_rpool_strdup_x
__P((SM_RPOOL_T
*rpool
, const char *s
));
172 #else /* DO_NOT_USE_STRCPY */
173 # define sm_rpool_strdup_x(rpool, str) \
174 strcpy(sm_rpool_malloc_x(rpool, strlen(str) + 1), str)
175 #endif /* DO_NOT_USE_STRCPY */
177 extern SM_RPOOL_ATTACH_T
178 sm_rpool_attach_x
__P((
180 SM_RPOOL_RFREE_T _rfree
,
183 # define sm_rpool_detach(a) ((void)(*(a) = NULL))
186 sm_rpool_setsizes
__P((
189 size_t _bigobjectsize
));
191 #endif /* ! SM_RPOOL_H */