167 |
return pool; |
return pool; |
168 |
} |
} |
169 |
|
|
170 |
|
/* Creates a pool, allocates a block STRUCT_SIZE bytes in |
171 |
|
length from it, stores the pool's address at offset |
172 |
|
POOL_MEMBER_OFFSET within the block, and returns the allocated |
173 |
|
block. |
174 |
|
|
175 |
|
Meant for use indirectly via pool_create_container(). */ |
176 |
|
void * |
177 |
|
pool_create_at_offset (size_t struct_size, size_t pool_member_offset) |
178 |
|
{ |
179 |
|
struct pool *pool; |
180 |
|
char *struct_; |
181 |
|
|
182 |
|
assert (struct_size >= sizeof pool); |
183 |
|
assert (pool_member_offset <= struct_size - sizeof pool); |
184 |
|
|
185 |
|
pool = pool_create (); |
186 |
|
struct_ = pool_alloc (pool, struct_size); |
187 |
|
*(struct pool **) (struct_ + pool_member_offset) = pool; |
188 |
|
return struct_; |
189 |
|
} |
190 |
|
|
191 |
/* Destroy the specified pool, including all subpools. */ |
/* Destroy the specified pool, including all subpools. */ |
192 |
void |
void |
193 |
pool_destroy (struct pool *pool) |
pool_destroy (struct pool *pool) |
599 |
return subpool; |
return subpool; |
600 |
} |
} |
601 |
|
|
602 |
|
/* Makes SUBPOOL a subpool of POOL. |
603 |
|
SUBPOOL must not already have a parent pool. |
604 |
|
The subpool will be destroyed automatically when POOL is destroyed. |
605 |
|
It may also be destroyed explicitly in advance. */ |
606 |
|
void |
607 |
|
pool_add_subpool (struct pool *pool, struct pool *subpool) |
608 |
|
{ |
609 |
|
struct pool_gizmo *g; |
610 |
|
|
611 |
|
assert (pool != NULL); |
612 |
|
assert (subpool != NULL); |
613 |
|
assert (subpool->parent == NULL); |
614 |
|
|
615 |
|
g = pool_alloc (subpool, sizeof *g); |
616 |
|
g->type = POOL_GIZMO_SUBPOOL; |
617 |
|
g->p.subpool = subpool; |
618 |
|
add_gizmo (pool, g); |
619 |
|
|
620 |
|
subpool->parent = pool; |
621 |
|
} |
622 |
|
|
623 |
/* Opens file FILENAME with mode MODE and returns a handle to it |
/* Opens file FILENAME with mode MODE and returns a handle to it |
624 |
if successful or a null pointer if not. |
if successful or a null pointer if not. |
625 |
The file will be closed automatically when POOL is destroyed, or it |
The file will be closed automatically when POOL is destroyed, or it |