45 #define ALLOCATOR_OVERHEAD 48 53 for (count = 1; size; size >>= 1, count++);
63 size_t size,
const char *
file,
int lineno,
const char *func)
73 pool->
prev = *pool_head;
74 pool->
size = alloc_size -
sizeof(*pool);
105 const char *
file,
int lineno,
const char *func)
113 switch (cleanup_type) {
128 if (*pool_head ==
NULL) {
132 preserve = *pool_head;
144 if (cur != preserve) {
150 *pool_head = preserve;
172 int needed,
const char *
file,
int lineno,
const char *func)
174 const char **p = (
const char **) pool_head + 1;
175 size_t initial_vector_size = ((size_t) (((
char *)mgr) - ((
char *)p))) /
sizeof(*p);
204 const char *
file,
int lineno,
const char *func)
207 size_t space = (*pool_head)->size - (*pool_head)->used;
214 if (__builtin_expect(to_alloc > space, 0)) {
215 size_t new_size = (*pool_head)->size;
217 while (new_size < to_alloc) {
230 result = (*pool_head)->base + (*pool_head)->used;
231 (*pool_head)->used += to_alloc;
232 (*pool_head)->active += needed;
244 size_t space = (*pool_head)->size - (*pool_head)->used;
254 (*pool_head)->used +=
grow;
255 (*pool_head)->active +=
grow;
271 if ((ptr >= pool->base) && (ptr <= (pool->base + pool->size))) {
273 if (pool->active == 0) {
288 const char *
format, va_list ap,
289 const char *
file,
int lineno,
const char *func)
293 size_t space = (*pool_head)->size - (*pool_head)->used;
304 target = (
char *) *ptr;
322 res = vsnprintf(target, available, format, ap2);
334 needed = (size_t)res + 1;
336 if (needed > available) {
345 vsprintf(target, format, ap);
349 }
else if (*ptr != target) {
358 (*pool_head)->active += needed;
365 (*pool_head)->active +=
grow;
375 va_start(ap, format);
381 size_t field_mgr_offset,
size_t field_mgr_pool_offset,
size_t pool_size,
382 const char *
file,
int lineno,
const char *func)
387 size_t pool_size_needed =
sizeof(*pool) + pool_size;
391 size_t initial_vector_size;
395 allocation =
__ast_calloc(num_structs, size_to_alloc, file, lineno, func);
400 mgr = allocation + field_mgr_offset;
402 pool = allocation + struct_size;
403 pool_head = allocation + field_mgr_pool_offset;
404 p = (
const char **) pool_head + 1;
405 initial_vector_size = ((size_t) (((
char *)mgr) - ((
char *)p))) /
sizeof(*p);
419 pool->
size = size_to_alloc - struct_size -
sizeof(*pool);
425 struct ast_string_field_vector *right)
443 const char *
file,
int lineno,
const char *func)
446 struct ast_string_field_vector *dest = &(copy_mgr->
string_fields);
447 struct ast_string_field_vector *src = &(orig_mgr->
string_fields);
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc
Asterisk main include file. File version handling, generic pbx functions.
uint16_t ast_string_field_allocation
#define ast_alignof(type)
Return the number of bytes used in the alignment of type.
static void grow(struct ast_threadpool *pool, int delta)
Add threads to the threadpool.
#define __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, file, lineno, func)
struct ast_string_field_pool * embedded_pool
static pj_pool_t * pool
Global memory pool for configuration and timers.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
#define ALLOCATOR_OVERHEAD
int __ast_string_field_free_memory(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, enum ast_stringfield_cleanup_type cleanup_type, const char *file, int lineno, const char *func)
Internal cleanup function.
const char * ast_string_field
void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, va_list ap, const char *file, int lineno, const char *func)
void * __ast_calloc_with_stringfields(unsigned int num_structs, size_t struct_size, size_t field_mgr_offset, size_t field_mgr_pool_offset, size_t pool_size, const char *file, int lineno, const char *func)
struct ast_string_field_vector string_fields
static int add_string_pool(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t size, const char *file, int lineno, const char *func)
add a new block to the pool. We can only allocate from the topmost pool, so the fields in *mgr reflec...
#define AST_STRING_FIELD_ALLOCATION(x)
Macro to provide access to the allocation field that lives immediately in front of a string field...
int __ast_string_field_ptr_grow(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t needed, const ast_string_field *ptr)
#define ast_make_room_for(offset, type)
Increase offset by the required alignment of type and make sure it is a multiple of said alignment...
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
static void reset_field(const char **p)
static size_t optimal_alloc_size(size_t size)
ast_string_field_allocation allocation
ast_string_field __ast_string_field_empty
int __ast_string_field_init(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, int needed, const char *file, int lineno, const char *func)
Internal initialization function.
int __ast_string_fields_cmp(struct ast_string_field_vector *left, struct ast_string_field_vector *right)
static int available(struct dahdi_pvt **pvt, int is_specific_channel)
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
void __ast_string_field_release_active(struct ast_string_field_pool *pool_head, const ast_string_field ptr)
ast_stringfield_cleanup_type
struct ast_string_field_pool * prev
void __ast_string_field_ptr_build(const char *file, int lineno, const char *func, struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format,...)
#define ast_align_for(offset, type)
Increase offset so it is a multiple of the required alignment of type.
static const struct @425 __ast_string_field_empty_buffer
int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool, struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr, const char *file, int lineno, const char *func)
static snd_pcm_format_t format
ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, size_t needed, const char *file, int lineno, const char *func)
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
ast_string_field last_alloc
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.