8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / include / sm / rpool.h
blob18a34fa8151a24833cf65c6564421ae802422424
1 /*
2 * Copyright (c) 2000-2001, 2003 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
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.
19 #ifndef SM_RPOOL_H
20 # define SM_RPOOL_H
22 # include <sm/gen.h>
23 # include <sm/heap.h>
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;
35 struct sm_poollink
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;
45 struct sm_resource
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;
59 struct sm_rlist
61 SM_RESOURCE_T sm_rvec[SM_RLIST_MAX];
62 SM_RLIST_T *sm_rnext;
65 typedef struct
67 /* Points to SmRpoolMagic, or is NULL if rpool is freed. */
68 const char *sm_magic;
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;
80 ** Memory pools
83 /* Size of the next pool to be allocated, not including the header. */
84 size_t sm_poolsize;
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. */
97 char *sm_poolptr;
100 ** Number of bytes available in the current pool.
101 ** Initially 0. Set to 0 by sm_rpool_free.
104 size_t sm_poolavail;
106 /* Linked list of memory pools. Initially NULL. */
107 SM_POOLLINK_T *sm_pools;
110 ** Resource lists
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.
120 size_t sm_ravail;
122 /* Linked list of resource lists. Initially NULL. */
123 SM_RLIST_T *sm_rlists;
125 #if _FFR_PERF_RPOOL
126 int sm_nbigblocks;
127 int sm_npools;
128 #endif /* _FFR_PERF_RPOOL */
130 } SM_RPOOL_T;
132 extern SM_RPOOL_T *
133 sm_rpool_new_x __P((
134 SM_RPOOL_T *_parent));
136 extern void
137 sm_rpool_free __P((
138 SM_RPOOL_T *_rpool));
140 # if SM_HEAP_CHECK
141 extern void *
142 sm_rpool_malloc_tagged_x __P((
143 SM_RPOOL_T *_rpool,
144 size_t _size,
145 char *_file,
146 int _line,
147 int _group));
148 # define sm_rpool_malloc_x(rpool, size) \
149 sm_rpool_malloc_tagged_x(rpool, size, __FILE__, __LINE__, SmHeapGroup)
150 extern void *
151 sm_rpool_malloc_tagged __P((
152 SM_RPOOL_T *_rpool,
153 size_t _size,
154 char *_file,
155 int _line,
156 int _group));
157 # define sm_rpool_malloc(rpool, size) \
158 sm_rpool_malloc_tagged(rpool, size, __FILE__, __LINE__, SmHeapGroup)
159 # else /* SM_HEAP_CHECK */
160 extern void *
161 sm_rpool_malloc_x __P((
162 SM_RPOOL_T *_rpool,
163 size_t _size));
164 extern void *
165 sm_rpool_malloc __P((
166 SM_RPOOL_T *_rpool,
167 size_t _size));
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((
179 SM_RPOOL_T *_rpool,
180 SM_RPOOL_RFREE_T _rfree,
181 void *_rcontext));
183 # define sm_rpool_detach(a) ((void)(*(a) = NULL))
185 extern void
186 sm_rpool_setsizes __P((
187 SM_RPOOL_T *_rpool,
188 size_t _poolsize,
189 size_t _bigobjectsize));
191 #endif /* ! SM_RPOOL_H */