RTS API Documentation  1.10.11
switch_core_memory.c
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  * Michael Jerris <mike@jerris.com>
28  * Paul D. Tinsley <pdt at jackhammer.org>
29  *
30  *
31  * switch_core_memory.c -- Main Core Library (memory management)
32  *
33  */
34 
35 #include <switch.h>
36 #include "private/switch_apr_pvt.h"
38 
39 //#define DEBUG_ALLOC
40 //#define DEBUG_ALLOC2
41 //#define DEBUG_ALLOC_CUTOFF 0 /* Lower to zero to log all pool allocations when DEBUG_ALLOC is defined */
42 //#define DESTROY_POOLS
43 //#define INSTANTLY_DESTROY_POOLS
44 //#define LOCK_MORE
45 //#define USE_MEM_LOCK
46 //#define SWITCH_POOL_RECYCLE
47 #ifndef SWITCH_POOL_RECYCLE
48 #define PER_POOL_LOCK 1
49 #endif
50 #ifndef DEBUG_ALLOC_CUTOFF
51 #define DEBUG_ALLOC_CUTOFF 500
52 #endif
53 
54 static struct {
55 #ifdef USE_MEM_LOCK
56  switch_mutex_t *mem_lock;
57 #endif
58  switch_queue_t *pool_queue; /* 8 ball break */
63 
65 {
66  switch_assert(session != NULL);
67  switch_assert(session->pool != NULL);
68  return session->pool;
69 }
70 
71 /* **ONLY** alloc things with this function that **WILL NOT** outlive
72  the session itself or expect an earth shattering KABOOM!*/
73 SWITCH_DECLARE(void *) switch_core_perform_session_alloc(switch_core_session_t *session, switch_size_t memory, const char *file, const char *func,
74  int line)
75 {
76  void *ptr = NULL;
77  switch_assert(session != NULL);
78  switch_assert(session->pool != NULL);
79 
80 #ifdef LOCK_MORE
81 #ifdef USE_MEM_LOCK
83 #endif
84 #endif
85 
86 #ifdef DEBUG_ALLOC
87  if (memory > DEBUG_ALLOC_CUTOFF)
88  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p %p Session Allocate %s %d\n",
89  (void *) session->pool, (void *) session, fspr_pool_tag(session->pool, NULL), (int) memory);
90 #endif
91 
92 #if APR_POOL_DEBUG
93  ptr = fspr_palloc_debug(session->pool, memory, func);
94 #else
95  ptr = fspr_palloc(session->pool, memory);
96 #endif
97  switch_assert(ptr != NULL);
98 
99  memset(ptr, 0, memory);
100 
101 #ifdef LOCK_MORE
102 #ifdef USE_MEM_LOCK
104 #endif
105 #endif
106 
107  return ptr;
108 }
109 
110 /* **ONLY** alloc things with these functions that **WILL NOT** need
111  to be freed *EVER* ie this is for *PERMANENT* memory allocation */
112 
113 SWITCH_DECLARE(void *) switch_core_perform_permanent_alloc(switch_size_t memory, const char *file, const char *func, int line)
114 {
115  void *ptr = NULL;
116  switch_assert(memory_manager.memory_pool != NULL);
117 
118 #ifdef LOCK_MORE
119 #ifdef USE_MEM_LOCK
121 #endif
122 #endif
123 
124 #ifdef DEBUG_ALLOC
125  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Perm Allocate %s %d\n",
126  (void *)memory_manager.memory_pool, fspr_pool_tag(memory_manager.memory_pool, NULL), (int) memory);
127 #endif
128 
129  ptr = fspr_palloc(memory_manager.memory_pool, memory);
130 
131  switch_assert(ptr != NULL);
132  memset(ptr, 0, memory);
133 
134 #ifdef LOCK_MORE
135 #ifdef USE_MEM_LOCK
137 #endif
138 #endif
139 
140  return ptr;
141 }
142 
143 SWITCH_DECLARE(char *) switch_core_perform_permanent_strdup(const char *todup, const char *file, const char *func, int line)
144 {
145  char *duped = NULL;
146  switch_size_t len;
147  switch_assert(memory_manager.memory_pool != NULL);
148 
149  if (!todup) {
150  return NULL;
151  }
152 
153  if (zstr(todup)) {
154  return SWITCH_BLANK_STRING;
155  }
156 #ifdef LOCK_MORE
157 #ifdef USE_MEM_LOCK
159 #endif
160 #endif
161 
162  len = strlen(todup) + 1;
163  duped = fspr_pstrmemdup(memory_manager.memory_pool, todup, len);
164  switch_assert(duped != NULL);
165 
166 #ifdef DEBUG_ALLOC
167  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Perm Allocate %s %d\n",
168  (void *) memory_manager.memory_pool, fspr_pool_tag(memory_manager.memory_pool, NULL), (int) len);
169 #endif
170 
171 #ifdef LOCK_MORE
172 #ifdef USE_MEM_LOCK
174 #endif
175 #endif
176 
177  return duped;
178 }
179 
181 {
182  va_list ap;
183  char *result = NULL;
184 
185  va_start(ap, fmt);
186  result = switch_core_vsprintf(session->pool, fmt, ap);
187  va_end(ap);
188 
189  return result;
190 }
191 
192 SWITCH_DECLARE(char *) switch_core_session_vsprintf(switch_core_session_t *session, const char *fmt, va_list ap)
193 {
194  return switch_core_vsprintf(session->pool, fmt, ap);
195 }
196 
198 {
199  char *result = NULL;
200 
201  switch_assert(pool != NULL);
202 
203 #ifdef LOCK_MORE
204 #ifdef USE_MEM_LOCK
206 #endif
207 #endif
208 
209  result = fspr_pvsprintf(pool, fmt, ap);
210  switch_assert(result != NULL);
211 
212 #ifdef LOCK_MORE
213 #ifdef USE_MEM_LOCK
215 #endif
216 #endif
217 
218  return result;
219 }
220 
222 {
223  va_list ap;
224  char *result;
225  va_start(ap, fmt);
226  result = switch_core_vsprintf(pool, fmt, ap);
227  va_end(ap);
228 
229  return result;
230 }
231 
232 SWITCH_DECLARE(char *) switch_core_perform_session_strdup(switch_core_session_t *session, const char *todup, const char *file, const char *func, int line)
233 {
234  char *duped = NULL;
235 #ifdef DEBUG_ALLOC
236  switch_size_t len;
237 #endif
238 
239  switch_assert(session != NULL);
240  switch_assert(session->pool != NULL);
241 
242  if (!todup) {
243  return NULL;
244  }
245 
246  if (zstr(todup)) {
247  return SWITCH_BLANK_STRING;
248  }
249 #ifdef LOCK_MORE
250 #ifdef USE_MEM_LOCK
252 #endif
253 #endif
254 
255 
256 
257 #ifdef DEBUG_ALLOC
258  len = strlen(todup);
259  if (len > DEBUG_ALLOC_CUTOFF)
260  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p %p Sess Strdup Allocate %s %ld\n",
261  (void *) session->pool, (void *)session, fspr_pool_tag(session->pool, NULL), strlen(todup));
262 #endif
263 
264  duped = fspr_pstrdup(session->pool, todup);
265  switch_assert(duped != NULL);
266 
267 #ifdef LOCK_MORE
268 #ifdef USE_MEM_LOCK
270 #endif
271 #endif
272 
273  return duped;
274 }
275 
276 SWITCH_DECLARE(char *) switch_core_perform_strdup(switch_memory_pool_t *pool, const char *todup, const char *file, const char *func, int line)
277 {
278  return switch_core_perform_strndup(pool, todup, todup ? strlen(todup) + 1 : 0, file, func, line);
279 }
280 
281 SWITCH_DECLARE(char *) switch_core_perform_strndup(switch_memory_pool_t *pool, const char *todup, size_t len, const char *file, const char *func, int line)
282 {
283  char *duped = NULL;
284  switch_assert(pool != NULL);
285 
286  if (!todup) {
287  return NULL;
288  }
289 
290  if (zstr(todup)) {
291  return SWITCH_BLANK_STRING;
292  }
293 #ifdef LOCK_MORE
294 #ifdef USE_MEM_LOCK
296 #endif
297 #endif
298 
299 #ifdef DEBUG_ALLOC
300  if (len > DEBUG_ALLOC_CUTOFF)
301  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Core Strdup Allocate %s %d\n",
302  (void *) pool, fspr_pool_tag(pool, NULL), (int)len);
303 #endif
304 
305  duped = fspr_pstrmemdup(pool, todup, len);
306  switch_assert(duped != NULL);
307 
308 #ifdef LOCK_MORE
309 #ifdef USE_MEM_LOCK
311 #endif
312 #endif
313 
314  return duped;
315 }
316 
318 {
319  fspr_pool_userdata_set(data, key, NULL, pool);
320 }
321 
323 {
324  void *data = NULL;
325 
326  fspr_pool_userdata_get(&data, key, pool);
327 
328  return data;
329 }
330 
332 {
333  fspr_pool_tag(pool, tag);
334 }
335 
337 {
338 #ifdef PER_POOL_LOCK
339  fspr_thread_mutex_t *my_mutex;
340  fspr_pool_mutex_set(p, NULL);
341 #endif
342 
343  fspr_pool_clear(p);
344 
345 #ifdef PER_POOL_LOCK
346 
347  if ((fspr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, p)) != APR_SUCCESS) {
348  abort();
349  }
350 
351  fspr_pool_mutex_set(p, my_mutex);
352 
353 #endif
354 
355 }
356 
357 #if APR_POOL_DEBUG
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;
362  char *line = NULL;
363 
364  fspr_pool_userdata_get((void**)&line, "line", pool);
365  fspr_pool_get_stats(pool, &alloc, &total_alloc, &clear);
366 
367  if (stream) {
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);
369  } else {
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);
371  }
372  return 0;
373 }
374 #endif
375 
377 {
378 #if APR_POOL_DEBUG
379  if (runtime.memory_pool) {
380  fspr_pool_walk_tree_debug(runtime.memory_pool, switch_core_pool_stats_callback, (void *)stream);
381  }
382 #else
383  if (stream) {
384  stream->write_function(stream, "Unable to get core pool statictics. Please rebuild FreeSWITCH with --enable-pool-debug");
385  } else {
386  printf("Unable to get core pool statictics. Please rebuild FreeSWITCH with --enable-pool-debug");
387  }
388 #endif
389 }
390 
392 {
393  char *tmp;
394 #ifdef INSTANTLY_DESTROY_POOLS
395  fspr_pool_create(pool, NULL);
396  switch_assert(*pool != NULL);
397 #else
398 
399 #ifdef PER_POOL_LOCK
400  fspr_allocator_t *my_allocator = NULL;
401  fspr_thread_mutex_t *my_mutex;
402 #else
403  void *pop = NULL;
404 #endif
405 
406 #ifdef USE_MEM_LOCK
408 #endif
409  switch_assert(pool != NULL);
410 
411 #ifndef PER_POOL_LOCK
412  if (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
413  *pool = (switch_memory_pool_t *) pop;
414  } else {
415 #endif
416 
417 #ifdef PER_POOL_LOCK
418  if ((fspr_allocator_create(&my_allocator)) != APR_SUCCESS) {
419  abort();
420  }
421 
422 #if APR_POOL_DEBUG
423  if ((fspr_pool_create_ex_debug(pool, memory_manager.memory_pool, NULL, my_allocator, func)) != APR_SUCCESS) {
424 #else
425  if ((fspr_pool_create_ex(pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
426 #endif
427  abort();
428  }
429 
430  if ((fspr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, *pool)) != APR_SUCCESS) {
431  abort();
432  }
433 
434  fspr_allocator_mutex_set(my_allocator, my_mutex);
435  fspr_allocator_owner_set(my_allocator, *pool);
436 
437  fspr_pool_mutex_set(*pool, my_mutex);
438 
439 #else
440  fspr_pool_create(pool, NULL);
441  switch_assert(*pool != NULL);
442  }
443 #endif
444 #endif
445 
446  tmp = switch_core_sprintf(*pool, "%s:%d", file, line);
447  fspr_pool_tag(*pool, tmp);
448 
449 #if APR_POOL_DEBUG
450  fspr_pool_userdata_set(tmp, "line", NULL, *pool);
451 #endif
452 
453 #ifdef DEBUG_ALLOC2
454  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p New Pool %s\n", (void *) *pool, fspr_pool_tag(*pool, NULL));
455 #endif
456 
457 
458 #ifdef USE_MEM_LOCK
460 #endif
461 
462  return SWITCH_STATUS_SUCCESS;
463 }
464 
466 {
467  char *tmp;
468  const char *tag;
469  switch_memory_pool_t *tmp_pool = NULL;
470  switch_assert(pool != NULL);
471 
472  /* In tag we store who calls the pool creation.
473  Now we append it with who calls the pool destroy.
474  */
475  if (*pool) {
476  tmp_pool = *pool;
477  *pool = NULL;
478 
479  tag = fspr_pool_tag(tmp_pool, NULL);
480  tmp = switch_core_sprintf(tmp_pool, "%s,%s:%d", (tag ? tag : ""), file, line);
481  fspr_pool_tag(tmp_pool, tmp);
482  }
483 
484 #ifdef DEBUG_ALLOC2
485  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Free Pool %s\n", (void *) tmp_pool, fspr_pool_tag(tmp_pool, NULL));
486 #endif
487 
488 #ifdef INSTANTLY_DESTROY_POOLS
489 #ifdef USE_MEM_LOCK
491 #endif
492  fspr_pool_destroy(tmp_pool);
493 #ifdef USE_MEM_LOCK
495 #endif
496 #else
497  if ((memory_manager.pool_thread_running != 1) || (switch_queue_push(memory_manager.pool_queue, tmp_pool) != SWITCH_STATUS_SUCCESS)) {
498 #ifdef USE_MEM_LOCK
500 #endif
501 #if APR_POOL_DEBUG
502  fspr_pool_destroy_debug(tmp_pool, func);
503 #else
504  if (tmp_pool) {
505  fspr_pool_destroy(tmp_pool);
506  }
507 #endif
508 #ifdef USE_MEM_LOCK
509 
511 #endif
512  }
513 #endif
514 
515  return SWITCH_STATUS_SUCCESS;
516 }
517 
518 SWITCH_DECLARE(void *) switch_core_perform_alloc(switch_memory_pool_t *pool, switch_size_t memory, const char *file, const char *func, int line)
519 {
520  void *ptr = NULL;
521 
522  switch_assert(pool != NULL);
523 
524 #ifdef LOCK_MORE
525 #ifdef USE_MEM_LOCK
527 #endif
528 #endif
529 
530 #ifdef DEBUG_ALLOC
531  if (memory > DEBUG_ALLOC_CUTOFF)
532  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Core Allocate %s %d\n",
533  (void *) pool, fspr_pool_tag(pool, NULL), (int) memory);
534  /*switch_assert(memory < 20000); */
535 #endif
536 
537 #if APR_POOL_DEBUG
538  ptr = fspr_palloc_debug(pool, memory, func);
539 #else
540  ptr = fspr_palloc(pool, memory);
541 #endif
542  switch_assert(ptr != NULL);
543  memset(ptr, 0, memory);
544 
545 #ifdef LOCK_MORE
546 #ifdef USE_MEM_LOCK
548 #endif
549 #endif
550 
551  return ptr;
552 }
553 
555 {
556 #if !defined(PER_POOL_LOCK) && !defined(INSTANTLY_DESTROY_POOLS)
558  void *pop = NULL;
559  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled memory pool(s)\n",
560  switch_queue_size(memory_manager.pool_recycle_queue) + switch_queue_size(memory_manager.pool_queue));
561 
562  while (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
563  pool = (switch_memory_pool_t *) pop;
564  if (!pool) {
565  break;
566  }
567 #ifdef USE_MEM_LOCK
569 #endif
570  fspr_pool_destroy(pool);
571 #ifdef USE_MEM_LOCK
573 #endif
574  }
575 #endif
576  return;
577 }
578 
580 {
581  memory_manager.pool_thread_running = 1;
582 
583  while (memory_manager.pool_thread_running == 1) {
584  int len = switch_queue_size(memory_manager.pool_queue);
585 
586  if (len) {
587  int x = len, done = 0;
588 
589  switch_yield(1000000);
590 #ifdef USE_MEM_LOCK
592 #endif
593  while (x > 0) {
594  void *pop = NULL;
595  if (switch_queue_pop(memory_manager.pool_queue, &pop) != SWITCH_STATUS_SUCCESS || !pop) {
596  done = 1;
597  break;
598  }
599 #if defined(PER_POOL_LOCK) || defined(DESTROY_POOLS)
600 #ifdef USE_MEM_LOCK
602 #endif
603 
604 #ifdef DEBUG_ALLOC
605  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%p DESTROY POOL\n", (void *) pop);
606 #endif
607  fspr_pool_destroy(pop);
608 #ifdef USE_MEM_LOCK
610 #endif
611 #else
612  fspr_pool_mutex_set(pop, NULL);
613 #ifdef DEBUG_ALLOC
614  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%p DESTROY POOL\n", (void *) pop);
615 #endif
616  fspr_pool_clear(pop);
617  if (switch_queue_trypush(memory_manager.pool_recycle_queue, pop) != SWITCH_STATUS_SUCCESS) {
618 #ifdef USE_MEM_LOCK
620 #endif
621 #ifdef DEBUG_ALLOC
622  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%p DESTROY POOL\n", (void *) pop);
623 #endif
624  fspr_pool_destroy(pop);
625 #ifdef USE_MEM_LOCK
627 #endif
628 
629  }
630 #endif
631  x--;
632  }
633 #ifdef USE_MEM_LOCK
635 #endif
636  if (done) {
637  goto done;
638  }
639  } else {
640  switch_yield(1000000);
641  }
642  }
643 
644  done:
646 
647  {
648  void *pop = NULL;
649  while (switch_queue_trypop(memory_manager.pool_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
650 #ifdef USE_MEM_LOCK
652 #endif
653  fspr_pool_destroy(pop);
654  pop = NULL;
655 #ifdef USE_MEM_LOCK
657 #endif
658 
659  }
660  }
661 
662  memory_manager.pool_thread_running = 0;
663 
664  return NULL;
665 }
666 
667 #ifndef INSTANTLY_DESTROY_POOLS
669 #endif
670 
672 {
673 #ifndef INSTANTLY_DESTROY_POOLS
674  switch_status_t st;
675  void *pop = NULL;
676 
677  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n");
678 
679  memory_manager.pool_thread_running = 0;
680  switch_thread_join(&st, pool_thread_p);
681 
682 
683  while (switch_queue_trypop(memory_manager.pool_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
684  fspr_pool_destroy(pop);
685  }
686 #endif
687 }
688 
690 {
691 #ifndef INSTANTLY_DESTROY_POOLS
692  switch_threadattr_t *thd_attr;
693 #endif
694 #ifdef PER_POOL_LOCK
695  fspr_allocator_t *my_allocator = NULL;
696  fspr_thread_mutex_t *my_mutex;
697 #endif
698 
699  memset(&memory_manager, 0, sizeof(memory_manager));
700 
701 #ifdef PER_POOL_LOCK
702  if ((fspr_allocator_create(&my_allocator)) != APR_SUCCESS) {
703  abort();
704  }
705 
706  if ((fspr_pool_create_ex(&memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
707  fspr_allocator_destroy(my_allocator);
708  my_allocator = NULL;
709  abort();
710  }
711 
712  if ((fspr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, memory_manager.memory_pool)) != APR_SUCCESS) {
713  abort();
714  }
715 
716  fspr_allocator_mutex_set(my_allocator, my_mutex);
717  fspr_pool_mutex_set(memory_manager.memory_pool, my_mutex);
718  fspr_allocator_owner_set(my_allocator, memory_manager.memory_pool);
719  fspr_pool_tag(memory_manager.memory_pool, "core_pool");
720 #else
721  fspr_pool_create(&memory_manager.memory_pool, NULL);
722  switch_assert(memory_manager.memory_pool != NULL);
723 #endif
724 
725 #ifdef USE_MEM_LOCK
727 #endif
728 
729 #ifdef INSTANTLY_DESTROY_POOLS
730  {
731  void *foo;
732  foo = (void *) (intptr_t) pool_thread;
733  }
734 #else
735 
736  switch_queue_create(&memory_manager.pool_queue, 50000, memory_manager.memory_pool);
737  switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);
738 
739  switch_threadattr_create(&thd_attr, memory_manager.memory_pool);
740 
742  switch_thread_create(&pool_thread_p, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
743 
744  while (!memory_manager.pool_thread_running) {
746  }
747 #endif
748 
749  return memory_manager.memory_pool;
750 }
751 
752 /* For Emacs:
753  * Local Variables:
754  * mode:c
755  * indent-tabs-mode:t
756  * tab-width:4
757  * c-basic-offset:4
758  * End:
759  * For VIM:
760  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
761  */
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1238
#define SWITCH_THREAD_FUNC
#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)
Definition: switch_apr.c:683
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)
Definition: switch_apr.c:1264
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)
Definition: switch_apr.c:1243
static switch_thread_t * thread
Definition: switch_log.c:486
switch_memory_pool_t * switch_core_memory_init(void)
struct switch_runtime runtime
Definition: switch_core.c:86
switch_queue_t * pool_queue
void switch_core_pool_stats(switch_stream_handle_t *stream)
#define zstr(x)
Definition: switch_utils.h:314
int cJSON_bool fmt
Definition: switch_cJSON.h:150
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
void switch_core_memory_stop(void)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
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)
Definition: switch_apr.c:308
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
#define SWITCH_BLANK_STRING
Definition: switch_types.h:48
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1379
void switch_pool_clear(switch_memory_pool_t *p)
uintptr_t switch_size_t
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)
Definition: switch_time.c:658
int pool_thread_running
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
Definition: switch_apr.h:314
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
#define SWITCH_SIZE_T_FMT
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)
Main Library Header.
switch_memory_pool_t * switch_core_session_get_pool(switch_core_session_t *session)
#define SWITCH_DECLARE(type)
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)
Definition: switch_apr.c:1279
void switch_core_memory_pool_tag(switch_memory_pool_t *pool, const char *tag)
char * key
Definition: switch_msrp.c:64
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1253
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)
Definition: switch_apr.c:665
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)
Definition: switch_apr.c:698
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)
Definition: switch_apr.c:1233
switch_queue_t * pool_recycle_queue
void switch_core_memory_reclaim(void)
#define switch_assert(expr)
struct fspr_thread_t switch_thread_t
Definition: switch_apr.h:941
memset(buf, 0, buflen)
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)