47 #ifndef SWITCH_POOL_RECYCLE 48 #define PER_POOL_LOCK 1 50 #ifndef DEBUG_ALLOC_CUTOFF 51 #define DEBUG_ALLOC_CUTOFF 500 89 (
void *) session->
pool, (
void *) session, fspr_pool_tag(session->pool, NULL), (
int) memory);
93 ptr = fspr_palloc_debug(session->pool, memory, func);
95 ptr = fspr_palloc(session->pool, memory);
162 len = strlen(todup) + 1;
209 result = fspr_pvsprintf(pool, fmt, ap);
261 (
void *) session->
pool, (
void *)session, fspr_pool_tag(session->pool, NULL), strlen(todup));
264 duped = fspr_pstrdup(session->pool, todup);
302 (
void *) pool, fspr_pool_tag(pool, NULL), (
int)len);
305 duped = fspr_pstrmemdup(pool, todup, len);
319 fspr_pool_userdata_set(data, key, NULL, pool);
326 fspr_pool_userdata_get(&data, key, pool);
333 fspr_pool_tag(pool, tag);
339 fspr_thread_mutex_t *my_mutex;
340 fspr_pool_mutex_set(p, NULL);
347 if ((fspr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, p)) != APR_SUCCESS) {
351 fspr_pool_mutex_set(p, my_mutex);
358 static int switch_core_pool_stats_callback(fspr_pool_t *
pool,
void *data) {
360 size_t size = (size_t)fspr_pool_num_bytes(
pool, 1);
361 unsigned int alloc = 0, total_alloc = 0, clear = 0;
364 fspr_pool_userdata_get((
void**)&line,
"line",
pool);
365 fspr_pool_get_stats(
pool, &alloc, &total_alloc, &clear);
368 stream->
write_function(stream,
"Pool '%s' size: %" SWITCH_SIZE_T_FMT ", alloc:%d, total_alloc:%d, clear:%d\n", (line ? line : fspr_pool_tag(
pool, NULL)), size, alloc, total_alloc, clear);
370 printf(
"Pool '%s' size: %" SWITCH_SIZE_T_FMT ", alloc:%d, total_alloc:%d, clear:%d\n", (line ? line : fspr_pool_tag(
pool, NULL)), size, alloc, total_alloc, clear);
380 fspr_pool_walk_tree_debug(
runtime.
memory_pool, switch_core_pool_stats_callback, (
void *)stream);
384 stream->
write_function(stream,
"Unable to get core pool statictics. Please rebuild FreeSWITCH with --enable-pool-debug");
386 printf(
"Unable to get core pool statictics. Please rebuild FreeSWITCH with --enable-pool-debug");
394 #ifdef INSTANTLY_DESTROY_POOLS 395 fspr_pool_create(pool, NULL);
400 fspr_allocator_t *my_allocator = NULL;
401 fspr_thread_mutex_t *my_mutex;
411 #ifndef PER_POOL_LOCK 418 if ((fspr_allocator_create(&my_allocator)) != APR_SUCCESS) {
423 if ((fspr_pool_create_ex_debug(pool,
memory_manager.memory_pool, NULL, my_allocator, func)) != APR_SUCCESS) {
425 if ((fspr_pool_create_ex(pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
430 if ((fspr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, *pool)) != APR_SUCCESS) {
434 fspr_allocator_mutex_set(my_allocator, my_mutex);
435 fspr_allocator_owner_set(my_allocator, *pool);
437 fspr_pool_mutex_set(*pool, my_mutex);
440 fspr_pool_create(pool, NULL);
447 fspr_pool_tag(*pool, tmp);
450 fspr_pool_userdata_set(tmp,
"line", NULL, *pool);
479 tag = fspr_pool_tag(tmp_pool, NULL);
481 fspr_pool_tag(tmp_pool, tmp);
488 #ifdef INSTANTLY_DESTROY_POOLS 492 fspr_pool_destroy(tmp_pool);
502 fspr_pool_destroy_debug(tmp_pool, func);
505 fspr_pool_destroy(tmp_pool);
533 (
void *) pool, fspr_pool_tag(pool, NULL), (
int) memory);
538 ptr = fspr_palloc_debug(pool, memory, func);
540 ptr = fspr_palloc(pool, memory);
556 #if !defined(PER_POOL_LOCK) && !defined(INSTANTLY_DESTROY_POOLS) 570 fspr_pool_destroy(pool);
587 int x = len, done = 0;
599 #if defined(PER_POOL_LOCK) || defined(DESTROY_POOLS) 607 fspr_pool_destroy(pop);
612 fspr_pool_mutex_set(pop, NULL);
616 fspr_pool_clear(pop);
624 fspr_pool_destroy(pop);
653 fspr_pool_destroy(pop);
667 #ifndef INSTANTLY_DESTROY_POOLS 673 #ifndef INSTANTLY_DESTROY_POOLS 684 fspr_pool_destroy(pop);
691 #ifndef INSTANTLY_DESTROY_POOLS 695 fspr_allocator_t *my_allocator = NULL;
696 fspr_thread_mutex_t *my_mutex;
702 if ((fspr_allocator_create(&my_allocator)) != APR_SUCCESS) {
706 if ((fspr_pool_create_ex(&
memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
707 fspr_allocator_destroy(my_allocator);
712 if ((fspr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED,
memory_manager.memory_pool)) != APR_SUCCESS) {
716 fspr_allocator_mutex_set(my_allocator, my_mutex);
718 fspr_allocator_owner_set(my_allocator,
memory_manager.memory_pool);
729 #ifdef INSTANTLY_DESTROY_POOLS unsigned int switch_queue_size(switch_queue_t *queue)
#define SWITCH_CHANNEL_LOG
switch_status_t switch_core_perform_destroy_memory_pool(switch_memory_pool_t **pool, const char *file, const char *func, int line)
#define DEBUG_ALLOC_CUTOFF
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
switch_memory_pool_t * pool
switch_status_t switch_core_perform_new_memory_pool(switch_memory_pool_t **pool, const char *file, const char *func, int line)
static void *SWITCH_THREAD_FUNC pool_thread(switch_thread_t *thread, void *obj)
void * switch_core_memory_pool_get_data(switch_memory_pool_t *pool, const char *key)
char * switch_core_sprintf(switch_memory_pool_t *pool, const char *fmt,...)
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
char * switch_core_perform_strndup(switch_memory_pool_t *pool, const char *todup, size_t len, const char *file, const char *func, int line)
static struct @3 memory_manager
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
static switch_thread_t * thread
switch_memory_pool_t * switch_core_memory_init(void)
struct switch_runtime runtime
switch_queue_t * pool_queue
void switch_core_pool_stats(switch_stream_handle_t *stream)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
#define SWITCH_MUTEX_NESTED
void switch_core_memory_stop(void)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
char * switch_core_perform_session_strdup(switch_core_session_t *session, const char *todup, const char *file, const char *func, int line)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
#define SWITCH_THREAD_STACKSIZE
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
#define SWITCH_BLANK_STRING
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
void switch_pool_clear(switch_memory_pool_t *p)
char * switch_core_session_vsprintf(switch_core_session_t *session, const char *fmt, va_list ap)
printf-style style printing routine. The data is output to a string allocated from the session ...
void switch_cond_next(void)
void * switch_core_perform_permanent_alloc(switch_size_t memory, const char *file, const char *func, int line)
char * switch_core_perform_permanent_strdup(const char *todup, const char *file, const char *func, int line)
struct fspr_thread_mutex_t switch_mutex_t
switch_memory_pool_t * memory_pool
char * switch_core_perform_strdup(switch_memory_pool_t *pool, const char *todup, const char *file, const char *func, int line)
switch_stream_handle_write_function_t write_function
static switch_thread_t * pool_thread_p
switch_memory_pool_t * pool
switch_status_t
Common return values.
void * switch_core_perform_session_alloc(switch_core_session_t *session, switch_size_t memory, const char *file, const char *func, int line)
void switch_core_memory_pool_set_data(switch_memory_pool_t *pool, const char *key, void *data)
switch_memory_pool_t * switch_core_session_get_pool(switch_core_session_t *session)
char * switch_core_session_sprintf(switch_core_session_t *session, const char *fmt,...)
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
void switch_core_memory_pool_tag(switch_memory_pool_t *pool, const char *tag)
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
switch_memory_pool_t * memory_pool
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
struct fspr_pool_t switch_memory_pool_t
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
switch_queue_t * pool_recycle_queue
void switch_core_memory_reclaim(void)
struct fspr_thread_t switch_thread_t
void * switch_core_perform_alloc(switch_memory_pool_t *pool, switch_size_t memory, const char *file, const char *func, int line)
char * switch_core_vsprintf(switch_memory_pool_t *pool, const char *fmt, va_list ap)