Lines Matching defs:rpool

11 SM_RCSID("@(#)$Id: rpool.c,v 1.29 2013-11-22 20:51:43 ca Exp $")
15 ** For documentation, see rpool.html
20 #include <sm/rpool.h>
46 ** SM_RPOOL_ALLOCBLOCK_X -- allocate a new block for an rpool.
49 ** rpool -- rpool to which the block should be added.
60 sm_rpool_allocblock_x(rpool, size)
61 SM_RPOOL_T *rpool;
67 p->sm_pnext = rpool->sm_pools;
68 rpool->sm_pools = p;
73 ** SM_RPOOL_ALLOCBLOCK -- allocate a new block for an rpool.
76 ** rpool -- rpool to which the block should be added.
84 sm_rpool_allocblock(rpool, size)
85 SM_RPOOL_T *rpool;
93 p->sm_pnext = rpool->sm_pools;
94 rpool->sm_pools = p;
99 ** SM_RPOOL_MALLOC_TAGGED_X -- allocate memory from rpool
102 ** rpool -- rpool from which memory should be allocated;
116 ** if size == 0 and the rpool is new (no memory
120 ** - checking for rpool->sm_poolptr != NULL
126 sm_rpool_malloc_tagged_x(rpool, size, file, line, group)
127 SM_RPOOL_T *rpool;
133 sm_rpool_malloc_x(rpool, size)
134 SM_RPOOL_T *rpool;
140 if (rpool == NULL)
148 if (size <= rpool->sm_poolavail)
150 ptr = rpool->sm_poolptr;
151 rpool->sm_poolptr += size;
152 rpool->sm_poolavail -= size;
159 ** That's okay: we set rpool->sm_poolavail to 0 when we free an rpool,
163 SM_REQUIRE(rpool->sm_magic == SmRpoolMagic);
180 if (size > rpool->sm_bigobjectsize)
183 ++rpool->sm_nbigblocks;
185 return sm_rpool_allocblock_x(rpool, size);
187 SM_ASSERT(rpool->sm_bigobjectsize <= rpool->sm_poolsize);
188 ptr = sm_rpool_allocblock_x(rpool, rpool->sm_poolsize);
189 rpool->sm_poolptr = ptr + size;
190 rpool->sm_poolavail = rpool->sm_poolsize - size;
192 ++rpool->sm_npools;
198 ** SM_RPOOL_MALLOC_TAGGED -- allocate memory from rpool
201 ** rpool -- rpool from which memory should be allocated;
212 ** if size == 0 and the rpool is new (no memory
216 ** - checking for rpool->sm_poolptr != NULL
222 sm_rpool_malloc_tagged(rpool, size, file, line, group)
223 SM_RPOOL_T *rpool;
229 sm_rpool_malloc(rpool, size)
230 SM_RPOOL_T *rpool;
236 if (rpool == NULL)
244 if (size <= rpool->sm_poolavail)
246 ptr = rpool->sm_poolptr;
247 rpool->sm_poolptr += size;
248 rpool->sm_poolavail -= size;
255 ** That's okay: we set rpool->sm_poolavail to 0 when we free an rpool,
259 SM_REQUIRE(rpool->sm_magic == SmRpoolMagic);
276 if (size > rpool->sm_bigobjectsize)
279 ++rpool->sm_nbigblocks;
281 return sm_rpool_allocblock(rpool, size);
283 SM_ASSERT(rpool->sm_bigobjectsize <= rpool->sm_poolsize);
284 ptr = sm_rpool_allocblock(rpool, rpool->sm_poolsize);
287 rpool->sm_poolptr = ptr + size;
288 rpool->sm_poolavail = rpool->sm_poolsize - size;
290 ++rpool->sm_npools;
296 ** SM_RPOOL_NEW_X -- create a new rpool.
299 ** parent -- pointer to parent rpool, can be NULL.
302 ** Pointer to new rpool.
309 SM_RPOOL_T *rpool;
311 rpool = sm_malloc_x(sizeof(SM_RPOOL_T));
313 rpool->sm_parentlink = NULL;
317 rpool->sm_parentlink = sm_rpool_attach_x(parent,
319 (void *) rpool);
321 sm_free(rpool);
325 rpool->sm_magic = SmRpoolMagic;
327 rpool->sm_poolsize = POOLSIZE - sizeof(SM_POOLHDR_T);
328 rpool->sm_bigobjectsize = rpool->sm_poolsize / BIG_OBJECT_RATIO;
329 rpool->sm_poolptr = NULL;
330 rpool->sm_poolavail = 0;
331 rpool->sm_pools = NULL;
333 rpool->sm_rptr = NULL;
334 rpool->sm_ravail = 0;
335 rpool->sm_rlists = NULL;
337 rpool->sm_nbigblocks = 0;
338 rpool->sm_npools = 0;
341 return rpool;
345 ** SM_RPOOL_SETSIZES -- set sizes for rpool.
348 ** poolsize -- size of a single rpool block.
357 sm_rpool_setsizes(rpool, poolsize, bigobjectsize)
358 SM_RPOOL_T *rpool;
367 rpool->sm_poolsize = poolsize;
368 rpool->sm_bigobjectsize = bigobjectsize;
372 ** SM_RPOOL_FREE -- free an rpool and release all of its resources.
375 ** rpool -- rpool to free.
382 sm_rpool_free(rpool)
383 SM_RPOOL_T *rpool;
389 if (rpool == NULL)
398 rl = rpool->sm_rlists;
401 rmax = rpool->sm_rptr;
422 for (pp = rpool->sm_pools; pp != NULL; pp = pnext)
429 ** Disconnect rpool from its parent.
432 if (rpool->sm_parentlink != NULL)
433 *rpool->sm_parentlink = NULL;
437 ** to use the rpool after it is freed will cause an assertion failure.
440 rpool->sm_magic = NULL;
441 rpool->sm_poolavail = 0;
442 rpool->sm_ravail = 0;
445 if (rpool->sm_nbigblocks > 0 || rpool->sm_npools > 1)
447 "perf: rpool=%lx, sm_nbigblocks=%d, sm_npools=%d",
448 (long) rpool, rpool->sm_nbigblocks, rpool->sm_npools);
449 rpool->sm_nbigblocks = 0;
450 rpool->sm_npools = 0;
452 sm_free(rpool);
456 ** SM_RPOOL_ATTACH_X -- attach a resource to an rpool.
459 ** rpool -- rpool to which resource should be attached.
460 ** rfree -- function to call when rpool is freed.
461 ** rcontext -- argument for function to call when rpool is freed.
471 sm_rpool_attach_x(rpool, rfree, rcontext)
472 SM_RPOOL_T *rpool;
479 SM_REQUIRE_ISA(rpool, SmRpoolMagic);
481 if (rpool->sm_ravail == 0)
484 rl->sm_rnext = rpool->sm_rlists;
485 rpool->sm_rlists = rl;
486 rpool->sm_rptr = rl->sm_rvec;
487 rpool->sm_ravail = SM_RLIST_MAX;
490 a = &rpool->sm_rptr->sm_rfree;
491 rpool->sm_rptr->sm_rfree = rfree;
492 rpool->sm_rptr->sm_rcontext = rcontext;
493 ++rpool->sm_rptr;
494 --rpool->sm_ravail;
503 ** rpool -- rpool to use.
511 sm_rpool_strdup_x(rpool, s)
512 SM_RPOOL_T *rpool;
520 n = sm_rpool_malloc_x(rpool, l + 1);