switch_core_memory.c File Reference

#include <switch.h>
#include "private/switch_core_pvt.h"

Include dependency graph for switch_core_memory.c:

Go to the source code of this file.

Defines

#define PER_POOL_LOCK   1

Functions

switch_memory_pool_tswitch_core_session_get_pool (switch_core_session_t *session)
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_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)
char * switch_core_session_sprintf (switch_core_session_t *session, const char *fmt,...)
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
char * switch_core_vsprintf (switch_memory_pool_t *pool, const char *fmt, va_list ap)
char * switch_core_sprintf (switch_memory_pool_t *pool, const char *fmt,...)
char * switch_core_perform_session_strdup (switch_core_session_t *session, const char *todup, const char *file, const char *func, int line)
char * switch_core_perform_strdup (switch_memory_pool_t *pool, const char *todup, 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)
void * switch_core_memory_pool_get_data (switch_memory_pool_t *pool, const char *key)
void switch_core_memory_pool_tag (switch_memory_pool_t *pool, const char *tag)
void switch_pool_clear (switch_memory_pool_t *p)
switch_status_t switch_core_perform_new_memory_pool (switch_memory_pool_t **pool, const char *file, const char *func, int line)
switch_status_t switch_core_perform_destroy_memory_pool (switch_memory_pool_t **pool, const char *file, const char *func, int line)
void * switch_core_perform_alloc (switch_memory_pool_t *pool, switch_size_t memory, const char *file, const char *func, int line)
void switch_core_memory_reclaim (void)
static void *SWITCH_THREAD_FUNC pool_thread (switch_thread_t *thread, void *obj)
void switch_core_memory_stop (void)
switch_memory_pool_tswitch_core_memory_init (void)

Variables

struct {
   switch_queue_t *   pool_queue
   switch_queue_t *   pool_recycle_queue
   switch_memory_pool_t *   memory_pool
   int   pool_thread_running
memory_manager
static switch_thread_tpool_thread_p = NULL


Define Documentation

#define PER_POOL_LOCK   1

Definition at line 46 of file switch_core_memory.c.


Function Documentation

static void* SWITCH_THREAD_FUNC pool_thread ( switch_thread_t thread,
void *  obj 
) [static]

Definition at line 504 of file switch_core_memory.c.

References memory_manager, switch_core_memory_reclaim(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_pop(), switch_queue_size(), switch_queue_trypop(), switch_queue_trypush(), SWITCH_STATUS_SUCCESS, and switch_yield.

Referenced by switch_core_memory_init().

00505 {
00506         memory_manager.pool_thread_running = 1;
00507 
00508         while (memory_manager.pool_thread_running == 1) {
00509                 int len = switch_queue_size(memory_manager.pool_queue);
00510 
00511                 if (len) {
00512                         int x = len, done = 0;
00513 
00514                         switch_yield(1000000);
00515 #ifdef USE_MEM_LOCK
00516                         switch_mutex_lock(memory_manager.mem_lock);
00517 #endif
00518                         while (x > 0) {
00519                                 void *pop = NULL;
00520                                 if (switch_queue_pop(memory_manager.pool_queue, &pop) != SWITCH_STATUS_SUCCESS || !pop) {
00521                                         done = 1;
00522                                         break;
00523                                 }
00524 #if defined(PER_POOL_LOCK) || defined(DESTROY_POOLS)
00525 #ifdef USE_MEM_LOCK
00526                                 switch_mutex_lock(memory_manager.mem_lock);
00527 #endif
00528                                 apr_pool_destroy(pop);
00529 #ifdef USE_MEM_LOCK
00530                                 switch_mutex_unlock(memory_manager.mem_lock);
00531 #endif
00532 #else
00533                                 apr_pool_mutex_set(pop, NULL);
00534                                 apr_pool_clear(pop);
00535                                 if (switch_queue_trypush(memory_manager.pool_recycle_queue, pop) != SWITCH_STATUS_SUCCESS) {
00536 #ifdef USE_MEM_LOCK
00537                                         switch_mutex_lock(memory_manager.mem_lock);
00538 #endif
00539                                         apr_pool_destroy(pop);
00540 #ifdef USE_MEM_LOCK
00541                                         switch_mutex_unlock(memory_manager.mem_lock);
00542 #endif
00543 
00544                                 }
00545 #endif
00546                                 x--;
00547                         }
00548 #ifdef USE_MEM_LOCK
00549                         switch_mutex_unlock(memory_manager.mem_lock);
00550 #endif
00551                         if (done) {
00552                                 goto done;
00553                         }
00554                 } else {
00555                         switch_yield(1000000);
00556                 }
00557         }
00558 
00559   done:
00560         switch_core_memory_reclaim();
00561 
00562         {
00563                 void *pop = NULL;
00564                 while (switch_queue_trypop(memory_manager.pool_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
00565 #ifdef USE_MEM_LOCK
00566                         switch_mutex_lock(memory_manager.mem_lock);
00567 #endif
00568                         apr_pool_destroy(pop);
00569                         pop = NULL;
00570 #ifdef USE_MEM_LOCK
00571                         switch_mutex_unlock(memory_manager.mem_lock);
00572 #endif
00573 
00574                 }
00575         }
00576 
00577         memory_manager.pool_thread_running = 0;
00578 
00579         return NULL;
00580 }

switch_memory_pool_t* switch_core_memory_init ( void   ) 

Definition at line 598 of file switch_core_memory.c.

References memory_manager, pool_thread(), pool_thread_p, switch_assert, switch_cond_next(), switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_queue_create(), switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_detach_set(), and switch_threadattr_stacksize_set().

Referenced by switch_core_init().

00599 {
00600 #ifndef INSTANTLY_DESTROY_POOLS
00601         switch_threadattr_t *thd_attr;
00602 #endif
00603 #ifdef PER_POOL_LOCK
00604         apr_allocator_t *my_allocator = NULL;
00605         apr_thread_mutex_t *my_mutex;
00606 #endif
00607 
00608         memset(&memory_manager, 0, sizeof(memory_manager));
00609 
00610 #ifdef PER_POOL_LOCK
00611         if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) {
00612                 abort();
00613         }
00614 
00615         if ((apr_pool_create_ex(&memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
00616                 apr_allocator_destroy(my_allocator);
00617                 my_allocator = NULL;
00618                 abort();
00619         }
00620 
00621         if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, memory_manager.memory_pool)) != APR_SUCCESS) {
00622                 abort();
00623         }
00624 
00625         apr_allocator_mutex_set(my_allocator, my_mutex);
00626         apr_pool_mutex_set(memory_manager.memory_pool, my_mutex);
00627         apr_allocator_owner_set(my_allocator, memory_manager.memory_pool);
00628         apr_pool_tag(memory_manager.memory_pool, "core_pool");
00629 #else
00630         apr_pool_create(&memory_manager.memory_pool, NULL);
00631         switch_assert(memory_manager.memory_pool != NULL);
00632 #endif
00633 
00634 #ifdef USE_MEM_LOCK
00635         switch_mutex_init(&memory_manager.mem_lock, SWITCH_MUTEX_NESTED, memory_manager.memory_pool);
00636 #endif
00637 
00638 #ifdef INSTANTLY_DESTROY_POOLS
00639         {
00640                 void *foo;
00641                 foo = (void *) (intptr_t) pool_thread;
00642         }
00643 #else
00644 
00645         switch_queue_create(&memory_manager.pool_queue, 50000, memory_manager.memory_pool);
00646         switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);
00647 
00648         switch_threadattr_create(&thd_attr, memory_manager.memory_pool);
00649         switch_threadattr_detach_set(thd_attr, 1);
00650 
00651         switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
00652         switch_thread_create(&pool_thread_p, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
00653 
00654         while (!memory_manager.pool_thread_running) {
00655                 switch_cond_next();
00656         }
00657 #endif
00658 
00659         return memory_manager.memory_pool;
00660 }

void switch_core_memory_stop ( void   ) 

Definition at line 586 of file switch_core_memory.c.

References memory_manager, pool_thread_p, SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), and switch_thread_join().

Referenced by switch_core_destroy().

00587 {
00588 #ifndef INSTANTLY_DESTROY_POOLS
00589         switch_status_t st;
00590 
00591         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n");
00592 
00593         memory_manager.pool_thread_running = 0;
00594         switch_thread_join(&st, pool_thread_p);
00595 #endif
00596 }

void* switch_core_perform_alloc ( switch_memory_pool_t pool,
switch_size_t  memory,
const char *  file,
const char *  func,
int  line 
)

Definition at line 447 of file switch_core_memory.c.

References memory_manager, switch_assert, SWITCH_CHANNEL_ID_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), and switch_mutex_unlock().

00448 {
00449         void *ptr = NULL;
00450 
00451         switch_assert(pool != NULL);
00452 
00453 #ifdef LOCK_MORE
00454 #ifdef USE_MEM_LOCK
00455         switch_mutex_lock(memory_manager.mem_lock);
00456 #endif
00457 #endif
00458 
00459 #ifdef DEBUG_ALLOC
00460         if (memory > 500)
00461                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Core Allocate %s %d\n", 
00462                                                   apr_pool_tag(pool, NULL), (int) memory);
00463         /*switch_assert(memory < 20000); */
00464 #endif
00465 
00466         ptr = apr_palloc(pool, memory);
00467         switch_assert(ptr != NULL);
00468         memset(ptr, 0, memory);
00469 
00470 #ifdef LOCK_MORE
00471 #ifdef USE_MEM_LOCK
00472         switch_mutex_unlock(memory_manager.mem_lock);
00473 #endif
00474 #endif
00475 
00476         return ptr;
00477 }

switch_status_t switch_core_perform_destroy_memory_pool ( switch_memory_pool_t **  pool,
const char *  file,
const char *  func,
int  line 
)

Definition at line 414 of file switch_core_memory.c.

References memory_manager, switch_assert, SWITCH_CHANNEL_ID_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_push(), and SWITCH_STATUS_SUCCESS.

00415 {
00416         switch_assert(pool != NULL);
00417 
00418 #ifdef DEBUG_ALLOC2
00419         switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Free Pool %s\n", apr_pool_tag(*pool, NULL));
00420 #endif
00421 
00422 #ifdef INSTANTLY_DESTROY_POOLS
00423 #ifdef USE_MEM_LOCK
00424         switch_mutex_lock(memory_manager.mem_lock);
00425 #endif
00426         apr_pool_destroy(*pool);
00427 #ifdef USE_MEM_LOCK
00428         switch_mutex_unlock(memory_manager.mem_lock);
00429 #endif
00430 #else
00431         if ((memory_manager.pool_thread_running != 1) || (switch_queue_push(memory_manager.pool_queue, *pool) != SWITCH_STATUS_SUCCESS)) {
00432 #ifdef USE_MEM_LOCK
00433                 switch_mutex_lock(memory_manager.mem_lock);
00434 #endif
00435                 apr_pool_destroy(*pool);
00436 #ifdef USE_MEM_LOCK
00437                 switch_mutex_unlock(memory_manager.mem_lock);
00438 #endif
00439         }
00440 #endif
00441 
00442         *pool = NULL;
00443 
00444         return SWITCH_STATUS_SUCCESS;
00445 }

switch_status_t switch_core_perform_new_memory_pool ( switch_memory_pool_t **  pool,
const char *  file,
const char *  func,
int  line 
)

Definition at line 348 of file switch_core_memory.c.

References memory_manager, switch_assert, SWITCH_CHANNEL_ID_LOG, switch_core_sprintf(), SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), and SWITCH_STATUS_SUCCESS.

00349 {
00350         char *tmp;
00351 #ifdef INSTANTLY_DESTROY_POOLS
00352         apr_pool_create(pool, NULL);
00353         switch_assert(*pool != NULL);
00354 #else
00355 
00356 #ifdef PER_POOL_LOCK
00357         apr_allocator_t *my_allocator = NULL;
00358         apr_thread_mutex_t *my_mutex;
00359 #else
00360         void *pop = NULL;
00361 #endif
00362 
00363 #ifdef USE_MEM_LOCK
00364         switch_mutex_lock(memory_manager.mem_lock);
00365 #endif
00366         switch_assert(pool != NULL);
00367 
00368 #ifndef PER_POOL_LOCK
00369         if (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
00370                 *pool = (switch_memory_pool_t *) pop;
00371         } else {
00372 #endif
00373 
00374 #ifdef PER_POOL_LOCK
00375                 if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) {
00376                         abort();
00377                 }
00378 
00379                 if ((apr_pool_create_ex(pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
00380                         abort();
00381                 }
00382 
00383                 if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, *pool)) != APR_SUCCESS) {
00384                         abort();
00385                 }
00386 
00387                 apr_allocator_mutex_set(my_allocator, my_mutex);
00388                 apr_allocator_owner_set(my_allocator, *pool);
00389 
00390                 apr_pool_mutex_set(*pool, my_mutex);
00391 
00392 #else
00393                 apr_pool_create(pool, NULL);
00394                 switch_assert(*pool != NULL);
00395         }
00396 #endif
00397 #endif
00398 
00399         tmp = switch_core_sprintf(*pool, "%s:%d", file, line);
00400         apr_pool_tag(*pool, tmp);
00401 
00402 #ifdef DEBUG_ALLOC2
00403         switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "New Pool %s\n", apr_pool_tag(*pool, NULL));
00404 #endif
00405 
00406 
00407 #ifdef USE_MEM_LOCK
00408         switch_mutex_unlock(memory_manager.mem_lock);
00409 #endif
00410 
00411         return SWITCH_STATUS_SUCCESS;
00412 }

void* switch_core_perform_permanent_alloc ( switch_size_t  memory,
const char *  file,
const char *  func,
int  line 
)

Definition at line 104 of file switch_core_memory.c.

References memory_manager, switch_assert, SWITCH_CHANNEL_ID_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), and switch_mutex_unlock().

00105 {
00106         void *ptr = NULL;
00107         switch_assert(memory_manager.memory_pool != NULL);
00108 
00109 #ifdef LOCK_MORE
00110 #ifdef USE_MEM_LOCK
00111         switch_mutex_lock(memory_manager.mem_lock);
00112 #endif
00113 #endif
00114 
00115 #ifdef DEBUG_ALLOC
00116         switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Perm Allocate %s %d\n", 
00117                                           apr_pool_tag(memory_manager.memory_pool, NULL), (int) memory);
00118 #endif
00119 
00120         ptr = apr_palloc(memory_manager.memory_pool, memory);
00121 
00122         switch_assert(ptr != NULL);
00123         memset(ptr, 0, memory);
00124 
00125 #ifdef LOCK_MORE
00126 #ifdef USE_MEM_LOCK
00127         switch_mutex_unlock(memory_manager.mem_lock);
00128 #endif
00129 #endif
00130 
00131         return ptr;
00132 }

char* switch_core_perform_permanent_strdup ( const char *  todup,
const char *  file,
const char *  func,
int  line 
)

Definition at line 134 of file switch_core_memory.c.

References memory_manager, switch_assert, SWITCH_BLANK_STRING, SWITCH_CHANNEL_ID_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), and zstr.

00135 {
00136         char *duped = NULL;
00137         switch_size_t len;
00138         switch_assert(memory_manager.memory_pool != NULL);
00139 
00140         if (!todup) {
00141                 return NULL;
00142         }
00143 
00144         if (zstr(todup)) {
00145                 return SWITCH_BLANK_STRING;
00146         }
00147 #ifdef LOCK_MORE
00148 #ifdef USE_MEM_LOCK
00149         switch_mutex_lock(memory_manager.mem_lock);
00150 #endif
00151 #endif
00152 
00153         len = strlen(todup) + 1;
00154         duped = apr_pstrmemdup(memory_manager.memory_pool, todup, len);
00155         switch_assert(duped != NULL);
00156 
00157 #ifdef DEBUG_ALLOC
00158         switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Perm Allocate %s %d\n", 
00159                                           apr_pool_tag(memory_manager.memory_pool, NULL), (int) len);
00160 #endif
00161 
00162 #ifdef LOCK_MORE
00163 #ifdef USE_MEM_LOCK
00164         switch_mutex_unlock(memory_manager.mem_lock);
00165 #endif
00166 #endif
00167 
00168         return duped;
00169 }

void* switch_core_perform_session_alloc ( switch_core_session_t session,
switch_size_t  memory,
const char *  file,
const char *  func,
int  line 
)

Definition at line 68 of file switch_core_memory.c.

References memory_manager, switch_assert, SWITCH_CHANNEL_ID_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), and switch_mutex_unlock().

00070 {
00071         void *ptr = NULL;
00072         switch_assert(session != NULL);
00073         switch_assert(session->pool != NULL);
00074 
00075 #ifdef LOCK_MORE
00076 #ifdef USE_MEM_LOCK
00077         switch_mutex_lock(memory_manager.mem_lock);
00078 #endif
00079 #endif
00080 
00081 #ifdef DEBUG_ALLOC
00082         if (memory > 500)
00083                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Session Allocate %s %d\n", 
00084                                                   apr_pool_tag(session->pool, NULL), (int) memory);
00085 #endif
00086 
00087         ptr = apr_palloc(session->pool, memory);
00088         switch_assert(ptr != NULL);
00089 
00090         memset(ptr, 0, memory);
00091 
00092 #ifdef LOCK_MORE
00093 #ifdef USE_MEM_LOCK
00094         switch_mutex_unlock(memory_manager.mem_lock);
00095 #endif
00096 #endif
00097 
00098         return ptr;
00099 }

char* switch_core_perform_session_strdup ( switch_core_session_t session,
const char *  todup,
const char *  file,
const char *  func,
int  line 
)

Definition at line 223 of file switch_core_memory.c.

References memory_manager, switch_assert, SWITCH_BLANK_STRING, SWITCH_CHANNEL_ID_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), and zstr.

00224 {
00225         char *duped = NULL;
00226 #ifdef DEBUG_ALLOC
00227         switch_size_t len;
00228 #endif
00229 
00230         switch_assert(session != NULL);
00231         switch_assert(session->pool != NULL);
00232 
00233         if (!todup) {
00234                 return NULL;
00235         }
00236 
00237         if (zstr(todup)) {
00238                 return SWITCH_BLANK_STRING;
00239         }
00240 #ifdef LOCK_MORE
00241 #ifdef USE_MEM_LOCK
00242         switch_mutex_lock(memory_manager.mem_lock);
00243 #endif
00244 #endif
00245 
00246 
00247 
00248 #ifdef DEBUG_ALLOC
00249         len = strlen(todup);
00250         if (len > 500)
00251                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Sess Strdup Allocate %s %ld\n", 
00252                                                   apr_pool_tag(session->pool, NULL), strlen(todup));
00253 #endif
00254 
00255         duped = apr_pstrdup(session->pool, todup);
00256         switch_assert(duped != NULL);
00257 
00258 #ifdef LOCK_MORE
00259 #ifdef USE_MEM_LOCK
00260         switch_mutex_unlock(memory_manager.mem_lock);
00261 #endif
00262 #endif
00263 
00264         return duped;
00265 }

char* switch_core_perform_strdup ( switch_memory_pool_t pool,
const char *  todup,
const char *  file,
const char *  func,
int  line 
)

Definition at line 267 of file switch_core_memory.c.

References memory_manager, switch_assert, SWITCH_BLANK_STRING, SWITCH_CHANNEL_ID_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), and zstr.

00268 {
00269         char *duped = NULL;
00270         switch_size_t len;
00271         switch_assert(pool != NULL);
00272 
00273         if (!todup) {
00274                 return NULL;
00275         }
00276 
00277         if (zstr(todup)) {
00278                 return SWITCH_BLANK_STRING;
00279         }
00280 #ifdef LOCK_MORE
00281 #ifdef USE_MEM_LOCK
00282         switch_mutex_lock(memory_manager.mem_lock);
00283 #endif
00284 #endif
00285 
00286         len = strlen(todup) + 1;
00287 
00288 #ifdef DEBUG_ALLOC
00289         if (len > 500)
00290                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Core Strdup Allocate %s %d\n", 
00291                                                   apr_pool_tag(pool, NULL), (int)len);
00292 #endif
00293 
00294         duped = apr_pstrmemdup(pool, todup, len);
00295         switch_assert(duped != NULL);
00296 
00297 #ifdef LOCK_MORE
00298 #ifdef USE_MEM_LOCK
00299         switch_mutex_unlock(memory_manager.mem_lock);
00300 #endif
00301 #endif
00302 
00303         return duped;
00304 }

switch_memory_pool_t* switch_core_session_get_pool ( switch_core_session_t session  ) 

Definition at line 59 of file switch_core_memory.c.

References switch_assert.

00060 {
00061         switch_assert(session != NULL);
00062         switch_assert(session->pool != NULL);
00063         return session->pool;
00064 }

char* switch_core_session_sprintf ( switch_core_session_t session,
const char *  fmt,
  ... 
)

Definition at line 171 of file switch_core_memory.c.

References switch_core_vsprintf().

00172 {
00173         va_list ap;
00174         char *result = NULL;
00175 
00176         va_start(ap, fmt);
00177         result = switch_core_vsprintf(session->pool, fmt, ap);
00178         va_end(ap);
00179 
00180         return result;
00181 }

char* switch_core_sprintf ( switch_memory_pool_t pool,
const char *  fmt,
  ... 
)

Definition at line 212 of file switch_core_memory.c.

References switch_core_vsprintf().

00213 {
00214         va_list ap;
00215         char *result;
00216         va_start(ap, fmt);
00217         result = switch_core_vsprintf(pool, fmt, ap);
00218         va_end(ap);
00219 
00220         return result;
00221 }

char* switch_core_vsprintf ( switch_memory_pool_t pool,
const char *  fmt,
va_list  ap 
)

Definition at line 188 of file switch_core_memory.c.

References memory_manager, switch_assert, switch_mutex_lock(), and switch_mutex_unlock().

00189 {
00190         char *result = NULL;
00191 
00192         switch_assert(pool != NULL);
00193 
00194 #ifdef LOCK_MORE
00195 #ifdef USE_MEM_LOCK
00196         switch_mutex_lock(memory_manager.mem_lock);
00197 #endif
00198 #endif
00199 
00200         result = apr_pvsprintf(pool, fmt, ap);
00201         switch_assert(result != NULL);
00202 
00203 #ifdef LOCK_MORE
00204 #ifdef USE_MEM_LOCK
00205         switch_mutex_unlock(memory_manager.mem_lock);
00206 #endif
00207 #endif
00208 
00209         return result;
00210 }


Variable Documentation

struct { ... } memory_manager [static]

Referenced by pool_thread(), switch_core_memory_init(), switch_core_memory_reclaim(), switch_core_memory_stop(), switch_core_perform_alloc(), switch_core_perform_destroy_memory_pool(), switch_core_perform_new_memory_pool(), switch_core_perform_permanent_alloc(), switch_core_perform_permanent_strdup(), switch_core_perform_session_alloc(), switch_core_perform_session_strdup(), switch_core_perform_strdup(), and switch_core_vsprintf().

switch_memory_pool_t* memory_pool

Definition at line 55 of file switch_core_memory.c.

switch_queue_t* pool_queue

Definition at line 53 of file switch_core_memory.c.

switch_queue_t* pool_recycle_queue

Definition at line 54 of file switch_core_memory.c.

switch_thread_t* pool_thread_p = NULL [static]

Definition at line 583 of file switch_core_memory.c.

Referenced by switch_core_memory_init(), and switch_core_memory_stop().

int pool_thread_running

Definition at line 56 of file switch_core_memory.c.


Generated on Sun May 20 04:00:09 2012 for FreeSWITCH API Documentation by  doxygen 1.4.7