2007-03-29 22:34:40 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Michael Jerris <mike@jerris.com>
|
|
|
|
* Paul D. Tinsley <pdt at jackhammer.org>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_core_memory.c -- Main Core Library (memory management)
|
|
|
|
*
|
|
|
|
*/
|
2008-01-27 17:36:53 +00:00
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
#include <switch.h>
|
2007-05-14 17:10:46 +00:00
|
|
|
#include "private/switch_core_pvt.h"
|
2007-09-29 01:06:08 +00:00
|
|
|
/*#define LOCK_MORE*/
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
static struct {
|
2007-09-29 01:06:08 +00:00
|
|
|
switch_mutex_t *mem_lock;
|
|
|
|
switch_queue_t *pool_queue; /* 8 ball break */
|
2007-10-01 14:14:15 +00:00
|
|
|
switch_queue_t *pool_recycle_queue;
|
2007-03-29 22:34:40 +00:00
|
|
|
switch_memory_pool_t *memory_pool;
|
2007-09-29 01:06:08 +00:00
|
|
|
int pool_thread_running;
|
2007-05-10 16:56:29 +00:00
|
|
|
} memory_manager;
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_memory_pool_t *) switch_core_session_get_pool(switch_core_session_t *session)
|
|
|
|
{
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(session != NULL);
|
|
|
|
switch_assert(session->pool != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
return session->pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* **ONLY** alloc things with this function that **WILL NOT** outlive
|
|
|
|
the session itself or expect an earth shattering KABOOM!*/
|
|
|
|
SWITCH_DECLARE(void *) switch_core_session_alloc(switch_core_session_t *session, switch_size_t memory)
|
|
|
|
{
|
|
|
|
void *ptr = NULL;
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(session != NULL);
|
|
|
|
switch_assert(session->pool != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
#ifdef DEBUG_ALLOC
|
2007-09-29 01:06:08 +00:00
|
|
|
printf("Allocate %d\n", (int)memory);
|
2007-03-29 22:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
ptr = apr_palloc(session->pool, memory);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(ptr != NULL);
|
2007-09-29 01:06:08 +00:00
|
|
|
|
|
|
|
memset(ptr, 0, memory);
|
|
|
|
|
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
|
|
|
#endif
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* **ONLY** alloc things with these functions that **WILL NOT** need
|
|
|
|
to be freed *EVER* ie this is for *PERMANENT* memory allocation */
|
|
|
|
|
|
|
|
SWITCH_DECLARE(void *) switch_core_permanent_alloc(switch_size_t memory)
|
|
|
|
{
|
|
|
|
void *ptr = NULL;
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(memory_manager.memory_pool != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
|
|
|
#endif
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ALLOC
|
2007-09-29 01:06:08 +00:00
|
|
|
printf("Perm Allocate %d\n", (int)memory);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ptr = apr_palloc(memory_manager.memory_pool, memory);
|
|
|
|
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(ptr != NULL);
|
2007-09-29 01:06:08 +00:00
|
|
|
memset(ptr, 0, memory);
|
|
|
|
|
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
2007-03-29 22:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(char *) switch_core_permanent_strdup(const char *todup)
|
|
|
|
{
|
|
|
|
char *duped = NULL;
|
|
|
|
switch_size_t len;
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(memory_manager.memory_pool != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
if (!todup)
|
|
|
|
return NULL;
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
len = strlen(todup) + 1;
|
2007-09-29 01:06:08 +00:00
|
|
|
duped = apr_pstrmemdup(memory_manager.memory_pool, todup, len);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(duped != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ALLOC
|
2007-09-29 01:06:08 +00:00
|
|
|
printf("Perm Allocate %d\n", (int)len);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
2007-03-29 22:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return duped;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(char *) switch_core_session_sprintf(switch_core_session_t *session, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *result = NULL;
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
|
|
|
#endif
|
|
|
|
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(session != NULL);
|
|
|
|
switch_assert(session->pool != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
va_start(ap, fmt);
|
2007-09-29 01:06:08 +00:00
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
result = apr_pvsprintf(session->pool, fmt, ap);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(result != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:15:25 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_core_sprintf(switch_memory_pool_t *pool, const char *fmt, ...)
|
2007-03-29 22:34:40 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *result = NULL;
|
|
|
|
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(pool != NULL);
|
2007-09-29 01:06:08 +00:00
|
|
|
|
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
result = apr_pvsprintf(pool, fmt, ap);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(result != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(char *) switch_core_session_strdup(switch_core_session_t *session, const char *todup)
|
|
|
|
{
|
|
|
|
char *duped = NULL;
|
|
|
|
switch_size_t len;
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(session != NULL);
|
|
|
|
switch_assert(session->pool != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
if (!todup) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-29 01:06:08 +00:00
|
|
|
|
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
len = strlen(todup) + 1;
|
|
|
|
|
|
|
|
#ifdef DEBUG_ALLOC
|
2007-09-29 01:06:08 +00:00
|
|
|
printf("Allocate %d\n", (int)len);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
duped = apr_pstrmemdup(session->pool, todup, len);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(duped != NULL);
|
2007-09-29 01:06:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
2007-03-29 22:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return duped;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:15:25 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool_t *pool, const char *todup)
|
2007-03-29 22:34:40 +00:00
|
|
|
{
|
|
|
|
char *duped = NULL;
|
|
|
|
switch_size_t len;
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(pool != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
|
|
|
|
if (!todup) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
len = strlen(todup) + 1;
|
|
|
|
|
|
|
|
#ifdef DEBUG_ALLOC
|
2007-09-29 01:06:08 +00:00
|
|
|
printf("Allocate %d\n", (int)len);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
duped = apr_pstrmemdup(pool, todup, len);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(duped != NULL);
|
2007-09-29 01:06:08 +00:00
|
|
|
|
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
2007-03-29 22:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return duped;
|
|
|
|
}
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_perform_new_memory_pool(switch_memory_pool_t **pool, const char *file, const char *func, int line)
|
2007-03-29 22:34:40 +00:00
|
|
|
{
|
2007-09-29 01:06:08 +00:00
|
|
|
char *tmp;
|
2007-10-01 14:14:15 +00:00
|
|
|
void *pop;
|
2007-03-29 22:34:40 +00:00
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(pool != NULL);
|
2007-10-01 14:14:15 +00:00
|
|
|
|
|
|
|
if (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
*pool = (switch_memory_pool_t *) pop;
|
|
|
|
} else {
|
|
|
|
apr_pool_create(pool, NULL);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(*pool != NULL);
|
2007-10-01 14:14:15 +00:00
|
|
|
}
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
#ifdef DEBUG_ALLOC2
|
|
|
|
printf("New Pool %s %s:%d\n", file, func, line);
|
|
|
|
#endif
|
|
|
|
tmp = switch_core_sprintf(*pool, "%s:%d", func, line);
|
|
|
|
apr_pool_tag(*pool, tmp);
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
2008-01-27 17:36:53 +00:00
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_perform_destroy_memory_pool(switch_memory_pool_t **pool, const char *file, const char *func, int line)
|
2007-03-29 22:34:40 +00:00
|
|
|
{
|
2007-09-29 01:06:08 +00:00
|
|
|
//char tmp[128] = "";
|
|
|
|
|
|
|
|
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(pool != NULL);
|
2007-09-29 01:06:08 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ALLOC2
|
|
|
|
printf("Free Pool %s %s:%d\n", file, func, line);
|
|
|
|
#endif
|
|
|
|
|
2007-10-23 00:11:03 +00:00
|
|
|
if (switch_queue_push(memory_manager.pool_queue, *pool) != SWITCH_STATUS_SUCCESS) {
|
2007-10-04 17:25:06 +00:00
|
|
|
apr_pool_destroy(*pool);
|
|
|
|
}
|
2007-09-29 01:06:08 +00:00
|
|
|
*pool = NULL;
|
2008-01-27 17:36:53 +00:00
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:15:25 +00:00
|
|
|
SWITCH_DECLARE(void *) switch_core_alloc(switch_memory_pool_t *pool, switch_size_t memory)
|
2007-03-29 22:34:40 +00:00
|
|
|
{
|
|
|
|
void *ptr = NULL;
|
2007-09-29 01:06:08 +00:00
|
|
|
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(pool != NULL);
|
2007-03-29 22:34:40 +00:00
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
#ifdef DEBUG_ALLOC
|
2007-09-29 01:06:08 +00:00
|
|
|
printf("Allocate %d\n", (int)memory);
|
2007-12-11 19:23:57 +00:00
|
|
|
/*switch_assert(memory < 20000);*/
|
2007-09-29 01:06:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ptr = apr_palloc(pool, memory);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(ptr != NULL);
|
2007-09-29 01:06:08 +00:00
|
|
|
memset(ptr, 0, memory);
|
|
|
|
|
|
|
|
#ifdef LOCK_MORE
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
2007-03-29 22:34:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2007-10-04 17:25:06 +00:00
|
|
|
SWITCH_DECLARE(void) switch_core_memory_reclaim(void)
|
|
|
|
{
|
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
void *pop = NULL;
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled memory pool(s)\n",
|
|
|
|
switch_queue_size(memory_manager.pool_recycle_queue) + switch_queue_size(memory_manager.pool_queue));
|
|
|
|
|
|
|
|
while (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
pool = (switch_memory_pool_t *) pop;
|
|
|
|
if (!pool) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
apr_pool_destroy(pool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
static void *SWITCH_THREAD_FUNC pool_thread(switch_thread_t * thread, void *obj)
|
|
|
|
{
|
|
|
|
void *pop = NULL;
|
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
|
|
|
|
memory_manager.pool_thread_running = 1;
|
|
|
|
|
|
|
|
while (memory_manager.pool_thread_running == 1) {
|
|
|
|
int len = switch_queue_size(memory_manager.pool_queue);
|
|
|
|
|
|
|
|
if (len) {
|
|
|
|
int x = len, done = 0;
|
|
|
|
|
|
|
|
switch_yield(1000000);
|
|
|
|
switch_mutex_lock(memory_manager.mem_lock);
|
|
|
|
while (x > 0) {
|
|
|
|
if (switch_queue_pop(memory_manager.pool_queue, &pop) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pop) {
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pool = (switch_memory_pool_t *) pop;
|
2007-10-01 14:14:15 +00:00
|
|
|
apr_pool_clear(pool);
|
2007-10-04 17:25:06 +00:00
|
|
|
if (switch_queue_trypush(memory_manager.pool_recycle_queue, pool) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
apr_pool_destroy(pool);
|
|
|
|
}
|
2007-09-29 01:06:08 +00:00
|
|
|
pool = NULL;
|
|
|
|
x--;
|
|
|
|
}
|
|
|
|
switch_mutex_unlock(memory_manager.mem_lock);
|
|
|
|
if (done) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch_yield(100000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2007-10-04 17:25:06 +00:00
|
|
|
switch_core_memory_reclaim();
|
2007-10-01 14:14:15 +00:00
|
|
|
|
|
|
|
while (switch_queue_trypop(memory_manager.pool_queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
pool = (switch_memory_pool_t *) pop;
|
|
|
|
if (!pool) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
apr_pool_destroy(pool);
|
|
|
|
}
|
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
memory_manager.pool_thread_running = 0;
|
2008-01-27 17:36:53 +00:00
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void switch_core_memory_stop(void)
|
|
|
|
{
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n");
|
2007-10-04 17:25:06 +00:00
|
|
|
memory_manager.pool_thread_running = -1;
|
2007-09-29 01:06:08 +00:00
|
|
|
while(memory_manager.pool_thread_running) {
|
|
|
|
switch_yield(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-30 02:20:13 +00:00
|
|
|
switch_memory_pool_t *switch_core_memory_init(void)
|
2007-03-29 22:34:40 +00:00
|
|
|
{
|
2007-09-29 01:06:08 +00:00
|
|
|
switch_thread_t *thread;
|
|
|
|
switch_threadattr_t *thd_attr;
|
|
|
|
|
|
|
|
|
2007-05-10 16:56:29 +00:00
|
|
|
memset(&memory_manager, 0, sizeof(memory_manager));
|
2007-03-29 22:34:40 +00:00
|
|
|
|
2007-05-10 16:56:29 +00:00
|
|
|
apr_pool_create(&memory_manager.memory_pool, NULL);
|
2007-12-11 19:23:57 +00:00
|
|
|
switch_assert(memory_manager.memory_pool != NULL);
|
2007-09-29 01:06:08 +00:00
|
|
|
switch_mutex_init(&memory_manager.mem_lock, SWITCH_MUTEX_NESTED, memory_manager.memory_pool);
|
|
|
|
switch_queue_create(&memory_manager.pool_queue, 50000, memory_manager.memory_pool);
|
2007-10-01 14:14:15 +00:00
|
|
|
switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);
|
2007-09-29 01:06:08 +00:00
|
|
|
|
|
|
|
switch_threadattr_create(&thd_attr, memory_manager.memory_pool);
|
|
|
|
switch_threadattr_detach_set(thd_attr, 1);
|
|
|
|
|
|
|
|
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
|
|
|
switch_thread_create(&thread, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
|
|
|
|
|
|
|
|
while (!memory_manager.pool_thread_running) {
|
|
|
|
switch_yield(1000);
|
|
|
|
}
|
|
|
|
|
2007-05-10 16:56:29 +00:00
|
|
|
return memory_manager.memory_pool;
|
2007-03-29 22:34:40 +00:00
|
|
|
}
|
2008-01-27 17:36:53 +00:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
|
|
|
* indent-tabs-mode:t
|
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
|
|
|
*/
|