Lines Matching defs:rpool

13 SM_RCSID("@(#)$Id: rpool.c,v 1.28 2004/08/03 20:44:04 ca Exp $")
17 ** For documentation, see rpool.html
22 #include <sm/rpool.h>
48 ** SM_RPOOL_ALLOCBLOCK_X -- allocate a new block for an rpool.
51 ** rpool -- rpool to which the block should be added.
62 sm_rpool_allocblock_x(rpool, size)
63 SM_RPOOL_T *rpool;
69 p->sm_pnext = rpool->sm_pools;
70 rpool->sm_pools = p;
75 ** SM_RPOOL_ALLOCBLOCK -- allocate a new block for an rpool.
78 ** rpool -- rpool to which the block should be added.
86 sm_rpool_allocblock(rpool, size)
87 SM_RPOOL_T *rpool;
95 p->sm_pnext = rpool->sm_pools;
96 rpool->sm_pools = p;
101 ** SM_RPOOL_MALLOC_TAGGED_X -- allocate memory from rpool
104 ** rpool -- rpool from which memory should be allocated;
118 ** if size == 0 and the rpool is new (no memory
122 ** - checking for rpool->sm_poolptr != NULL
128 sm_rpool_malloc_tagged_x(rpool, size, file, line, group)
129 SM_RPOOL_T *rpool;
135 sm_rpool_malloc_x(rpool, size)
136 SM_RPOOL_T *rpool;
142 if (rpool == NULL)
150 if (size <= rpool->sm_poolavail)
152 ptr = rpool->sm_poolptr;
153 rpool->sm_poolptr += size;
154 rpool->sm_poolavail -= size;
161 ** That's okay: we set rpool->sm_poolavail to 0 when we free an rpool,
165 SM_REQUIRE(rpool->sm_magic == SmRpoolMagic);
182 if (size > rpool->sm_bigobjectsize)
185 ++rpool->sm_nbigblocks;
187 return sm_rpool_allocblock_x(rpool, size);
189 SM_ASSERT(rpool->sm_bigobjectsize <= rpool->sm_poolsize);
190 ptr = sm_rpool_allocblock_x(rpool, rpool->sm_poolsize);
191 rpool->sm_poolptr = ptr + size;
192 rpool->sm_poolavail = rpool->sm_poolsize - size;
194 ++rpool->sm_npools;
200 ** SM_RPOOL_MALLOC_TAGGED -- allocate memory from rpool
203 ** rpool -- rpool from which memory should be allocated;
214 ** if size == 0 and the rpool is new (no memory
218 ** - checking for rpool->sm_poolptr != NULL
224 sm_rpool_malloc_tagged(rpool, size, file, line, group)
225 SM_RPOOL_T *rpool;
231 sm_rpool_malloc(rpool, size)
232 SM_RPOOL_T *rpool;
238 if (rpool == NULL)
246 if (size <= rpool->sm_poolavail)
248 ptr = rpool->sm_poolptr;
249 rpool->sm_poolptr += size;
250 rpool->sm_poolavail -= size;
257 ** That's okay: we set rpool->sm_poolavail to 0 when we free an rpool,
261 SM_REQUIRE(rpool->sm_magic == SmRpoolMagic);
278 if (size > rpool->sm_bigobjectsize)
281 ++rpool->sm_nbigblocks;
283 return sm_rpool_allocblock(rpool, size);
285 SM_ASSERT(rpool->sm_bigobjectsize <= rpool->sm_poolsize);
286 ptr = sm_rpool_allocblock(rpool, rpool->sm_poolsize);
289 rpool->sm_poolptr = ptr + size;
290 rpool->sm_poolavail = rpool->sm_poolsize - size;
292 ++rpool->sm_npools;
298 ** SM_RPOOL_NEW_X -- create a new rpool.
301 ** parent -- pointer to parent rpool, can be NULL.
304 ** Pointer to new rpool.
311 SM_RPOOL_T *rpool;
313 rpool = sm_malloc_x(sizeof(SM_RPOOL_T));
315 rpool->sm_parentlink = NULL;
319 rpool->sm_parentlink = sm_rpool_attach_x(parent,
321 (void *) rpool);
323 sm_free(rpool);
327 rpool->sm_magic = SmRpoolMagic;
329 rpool->sm_poolsize = POOLSIZE - sizeof(SM_POOLHDR_T);
330 rpool->sm_bigobjectsize = rpool->sm_poolsize / BIG_OBJECT_RATIO;
331 rpool->sm_poolptr = NULL;
332 rpool->sm_poolavail = 0;
333 rpool->sm_pools = NULL;
335 rpool->sm_rptr = NULL;
336 rpool->sm_ravail = 0;
337 rpool->sm_rlists = NULL;
339 rpool->sm_nbigblocks = 0;
340 rpool->sm_npools = 0;
343 return rpool;
347 ** SM_RPOOL_SETSIZES -- set sizes for rpool.
350 ** poolsize -- size of a single rpool block.
359 sm_rpool_setsizes(rpool, poolsize, bigobjectsize)
360 SM_RPOOL_T *rpool;
369 rpool->sm_poolsize = poolsize;
370 rpool->sm_bigobjectsize = bigobjectsize;
374 ** SM_RPOOL_FREE -- free an rpool and release all of its resources.
377 ** rpool -- rpool to free.
384 sm_rpool_free(rpool)
385 SM_RPOOL_T *rpool;
391 if (rpool == NULL)
400 rl = rpool->sm_rlists;
403 rmax = rpool->sm_rptr;
424 for (pp = rpool->sm_pools; pp != NULL; pp = pnext)
431 ** Disconnect rpool from its parent.
434 if (rpool->sm_parentlink != NULL)
435 *rpool->sm_parentlink = NULL;
439 ** to use the rpool after it is freed will cause an assertion failure.
442 rpool->sm_magic = NULL;
443 rpool->sm_poolavail = 0;
444 rpool->sm_ravail = 0;
447 if (rpool->sm_nbigblocks > 0 || rpool->sm_npools > 1)
449 "perf: rpool=%lx, sm_nbigblocks=%d, sm_npools=%d",
450 (long) rpool, rpool->sm_nbigblocks, rpool->sm_npools);
451 rpool->sm_nbigblocks = 0;
452 rpool->sm_npools = 0;
454 sm_free(rpool);
458 ** SM_RPOOL_ATTACH_X -- attach a resource to an rpool.
461 ** rpool -- rpool to which resource should be attached.
462 ** rfree -- function to call when rpool is freed.
463 ** rcontext -- argument for function to call when rpool is freed.
473 sm_rpool_attach_x(rpool, rfree, rcontext)
474 SM_RPOOL_T *rpool;
481 SM_REQUIRE_ISA(rpool, SmRpoolMagic);
483 if (rpool->sm_ravail == 0)
486 rl->sm_rnext = rpool->sm_rlists;
487 rpool->sm_rlists = rl;
488 rpool->sm_rptr = rl->sm_rvec;
489 rpool->sm_ravail = SM_RLIST_MAX;
492 a = &rpool->sm_rptr->sm_rfree;
493 rpool->sm_rptr->sm_rfree = rfree;
494 rpool->sm_rptr->sm_rcontext = rcontext;
495 ++rpool->sm_rptr;
496 --rpool->sm_ravail;
505 ** rpool -- rpool to use.
513 sm_rpool_strdup_x(rpool, s)
514 SM_RPOOL_T *rpool;
522 n = sm_rpool_malloc_x(rpool, l + 1);