FreeSWITCH API Documentation  1.7.0
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>
37 
38 //#define DEBUG_ALLOC
39 //#define DEBUG_ALLOC2
40 //#define DESTROY_POOLS
41 //#define INSTANTLY_DESTROY_POOLS
42 //#define LOCK_MORE
43 //#define USE_MEM_LOCK
44 //#define SWITCH_POOL_RECYCLE
45 #ifndef SWITCH_POOL_RECYCLE
46 #define PER_POOL_LOCK 1
47 #endif
48 
49 static struct {
50 #ifdef USE_MEM_LOCK
51  switch_mutex_t *mem_lock;
52 #endif
53  switch_queue_t *pool_queue; /* 8 ball break */
58 
60 {
61  switch_assert(session != NULL);
62  switch_assert(session->pool != NULL);
63  return session->pool;
64 }
65 
66 /* **ONLY** alloc things with this function that **WILL NOT** outlive
67  the session itself or expect an earth shattering KABOOM!*/
68 SWITCH_DECLARE(void *) switch_core_perform_session_alloc(switch_core_session_t *session, switch_size_t memory, const char *file, const char *func,
69  int line)
70 {
71  void *ptr = NULL;
72  switch_assert(session != NULL);
73  switch_assert(session->pool != NULL);
74 
75 #ifdef LOCK_MORE
76 #ifdef USE_MEM_LOCK
78 #endif
79 #endif
80 
81 #ifdef DEBUG_ALLOC
82  if (memory > 500)
83  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p %p Session Allocate %s %d\n",
84  (void *) session->pool, (void *) session, apr_pool_tag(session->pool, NULL), (int) memory);
85 #endif
86 
87  ptr = apr_palloc(session->pool, memory);
88  switch_assert(ptr != NULL);
89 
90  memset(ptr, 0, memory);
91 
92 #ifdef LOCK_MORE
93 #ifdef USE_MEM_LOCK
95 #endif
96 #endif
97 
98  return ptr;
99 }
100 
101 /* **ONLY** alloc things with these functions that **WILL NOT** need
102  to be freed *EVER* ie this is for *PERMANENT* memory allocation */
103 
104 SWITCH_DECLARE(void *) switch_core_perform_permanent_alloc(switch_size_t memory, const char *file, const char *func, int line)
105 {
106  void *ptr = NULL;
107  switch_assert(memory_manager.memory_pool != NULL);
108 
109 #ifdef LOCK_MORE
110 #ifdef USE_MEM_LOCK
112 #endif
113 #endif
114 
115 #ifdef DEBUG_ALLOC
116  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Perm Allocate %s %d\n",
117  (void *)memory_manager.memory_pool, apr_pool_tag(memory_manager.memory_pool, NULL), (int) memory);
118 #endif
119 
120  ptr = apr_palloc(memory_manager.memory_pool, memory);
121 
122  switch_assert(ptr != NULL);
123  memset(ptr, 0, memory);
124 
125 #ifdef LOCK_MORE
126 #ifdef USE_MEM_LOCK
128 #endif
129 #endif
130 
131  return ptr;
132 }
133 
134 SWITCH_DECLARE(char *) switch_core_perform_permanent_strdup(const char *todup, const char *file, const char *func, int line)
135 {
136  char *duped = NULL;
137  switch_size_t len;
138  switch_assert(memory_manager.memory_pool != NULL);
139 
140  if (!todup) {
141  return NULL;
142  }
143 
144  if (zstr(todup)) {
145  return SWITCH_BLANK_STRING;
146  }
147 #ifdef LOCK_MORE
148 #ifdef USE_MEM_LOCK
150 #endif
151 #endif
152 
153  len = strlen(todup) + 1;
154  duped = apr_pstrmemdup(memory_manager.memory_pool, todup, len);
155  switch_assert(duped != NULL);
156 
157 #ifdef DEBUG_ALLOC
158  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Perm Allocate %s %d\n",
159  (void *) memory_manager.memory_pool, apr_pool_tag(memory_manager.memory_pool, NULL), (int) len);
160 #endif
161 
162 #ifdef LOCK_MORE
163 #ifdef USE_MEM_LOCK
165 #endif
166 #endif
167 
168  return duped;
169 }
170 
171 SWITCH_DECLARE(char *) switch_core_session_sprintf(switch_core_session_t *session, const char *fmt, ...)
172 {
173  va_list ap;
174  char *result = NULL;
175 
176  va_start(ap, fmt);
177  result = switch_core_vsprintf(session->pool, fmt, ap);
178  va_end(ap);
179 
180  return result;
181 }
182 
183 SWITCH_DECLARE(char *) switch_core_session_vsprintf(switch_core_session_t *session, const char *fmt, va_list ap)
184 {
185  return switch_core_vsprintf(session->pool, fmt, ap);
186 }
187 
188 SWITCH_DECLARE(char *) switch_core_vsprintf(switch_memory_pool_t *pool, const char *fmt, va_list ap)
189 {
190  char *result = NULL;
191 
192  switch_assert(pool != NULL);
193 
194 #ifdef LOCK_MORE
195 #ifdef USE_MEM_LOCK
197 #endif
198 #endif
199 
200  result = apr_pvsprintf(pool, fmt, ap);
201  switch_assert(result != NULL);
202 
203 #ifdef LOCK_MORE
204 #ifdef USE_MEM_LOCK
206 #endif
207 #endif
208 
209  return result;
210 }
211 
213 {
214  va_list ap;
215  char *result;
216  va_start(ap, fmt);
217  result = switch_core_vsprintf(pool, fmt, ap);
218  va_end(ap);
219 
220  return result;
221 }
222 
223 SWITCH_DECLARE(char *) switch_core_perform_session_strdup(switch_core_session_t *session, const char *todup, const char *file, const char *func, int line)
224 {
225  char *duped = NULL;
226 #ifdef DEBUG_ALLOC
227  switch_size_t len;
228 #endif
229 
230  switch_assert(session != NULL);
231  switch_assert(session->pool != NULL);
232 
233  if (!todup) {
234  return NULL;
235  }
236 
237  if (zstr(todup)) {
238  return SWITCH_BLANK_STRING;
239  }
240 #ifdef LOCK_MORE
241 #ifdef USE_MEM_LOCK
243 #endif
244 #endif
245 
246 
247 
248 #ifdef DEBUG_ALLOC
249  len = strlen(todup);
250  if (len > 500)
251  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p %p Sess Strdup Allocate %s %ld\n",
252  (void *) session->pool, (void *)session, apr_pool_tag(session->pool, NULL), strlen(todup));
253 #endif
254 
255  duped = apr_pstrdup(session->pool, todup);
256  switch_assert(duped != NULL);
257 
258 #ifdef LOCK_MORE
259 #ifdef USE_MEM_LOCK
261 #endif
262 #endif
263 
264  return duped;
265 }
266 
267 SWITCH_DECLARE(char *) switch_core_perform_strdup(switch_memory_pool_t *pool, const char *todup, const char *file, const char *func, int line)
268 {
269  char *duped = NULL;
270  switch_size_t len;
271  switch_assert(pool != NULL);
272 
273  if (!todup) {
274  return NULL;
275  }
276 
277  if (zstr(todup)) {
278  return SWITCH_BLANK_STRING;
279  }
280 #ifdef LOCK_MORE
281 #ifdef USE_MEM_LOCK
283 #endif
284 #endif
285 
286  len = strlen(todup) + 1;
287 
288 #ifdef DEBUG_ALLOC
289  if (len > 500)
290  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Core Strdup Allocate %s %d\n",
291  (void *) pool, apr_pool_tag(pool, NULL), (int)len);
292 #endif
293 
294  duped = apr_pstrmemdup(pool, todup, len);
295  switch_assert(duped != NULL);
296 
297 #ifdef LOCK_MORE
298 #ifdef USE_MEM_LOCK
300 #endif
301 #endif
302 
303  return duped;
304 }
305 
307 {
308  apr_pool_userdata_set(data, key, NULL, pool);
309 }
310 
312 {
313  void *data = NULL;
314 
315  apr_pool_userdata_get(&data, key, pool);
316 
317  return data;
318 }
319 
321 {
322  apr_pool_tag(pool, tag);
323 }
324 
326 {
327 #ifdef PER_POOL_LOCK
328  apr_thread_mutex_t *my_mutex;
329  apr_pool_mutex_set(p, NULL);
330 #endif
331 
332  apr_pool_clear(p);
333 
334 #ifdef PER_POOL_LOCK
335 
336  if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, p)) != APR_SUCCESS) {
337  abort();
338  }
339 
340  apr_pool_mutex_set(p, my_mutex);
341 
342 #endif
343 
344 }
345 
346 
347 
349 {
350  char *tmp;
351 #ifdef INSTANTLY_DESTROY_POOLS
352  apr_pool_create(pool, NULL);
353  switch_assert(*pool != NULL);
354 #else
355 
356 #ifdef PER_POOL_LOCK
357  apr_allocator_t *my_allocator = NULL;
358  apr_thread_mutex_t *my_mutex;
359 #else
360  void *pop = NULL;
361 #endif
362 
363 #ifdef USE_MEM_LOCK
365 #endif
366  switch_assert(pool != NULL);
367 
368 #ifndef PER_POOL_LOCK
369  if (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
370  *pool = (switch_memory_pool_t *) pop;
371  } else {
372 #endif
373 
374 #ifdef PER_POOL_LOCK
375  if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) {
376  abort();
377  }
378 
379  if ((apr_pool_create_ex(pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
380  abort();
381  }
382 
383  if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, *pool)) != APR_SUCCESS) {
384  abort();
385  }
386 
387  apr_allocator_mutex_set(my_allocator, my_mutex);
388  apr_allocator_owner_set(my_allocator, *pool);
389 
390  apr_pool_mutex_set(*pool, my_mutex);
391 
392 #else
393  apr_pool_create(pool, NULL);
394  switch_assert(*pool != NULL);
395  }
396 #endif
397 #endif
398 
399  tmp = switch_core_sprintf(*pool, "%s:%d", file, line);
400  apr_pool_tag(*pool, tmp);
401 
402 #ifdef DEBUG_ALLOC2
403  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p New Pool %s\n", (void *) *pool, apr_pool_tag(*pool, NULL));
404 #endif
405 
406 
407 #ifdef USE_MEM_LOCK
409 #endif
410 
411  return SWITCH_STATUS_SUCCESS;
412 }
413 
415 {
416  switch_assert(pool != NULL);
417 
418 #ifdef DEBUG_ALLOC2
419  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Free Pool %s\n", (void *) *pool, apr_pool_tag(*pool, NULL));
420 #endif
421 
422 #ifdef INSTANTLY_DESTROY_POOLS
423 #ifdef USE_MEM_LOCK
425 #endif
426  apr_pool_destroy(*pool);
427 #ifdef USE_MEM_LOCK
429 #endif
430 #else
431  if ((memory_manager.pool_thread_running != 1) || (switch_queue_push(memory_manager.pool_queue, *pool) != SWITCH_STATUS_SUCCESS)) {
432 #ifdef USE_MEM_LOCK
434 #endif
435  apr_pool_destroy(*pool);
436 #ifdef USE_MEM_LOCK
438 #endif
439  }
440 #endif
441 
442  *pool = NULL;
443 
444  return SWITCH_STATUS_SUCCESS;
445 }
446 
447 SWITCH_DECLARE(void *) switch_core_perform_alloc(switch_memory_pool_t *pool, switch_size_t memory, const char *file, const char *func, int line)
448 {
449  void *ptr = NULL;
450 
451  switch_assert(pool != NULL);
452 
453 #ifdef LOCK_MORE
454 #ifdef USE_MEM_LOCK
456 #endif
457 #endif
458 
459 #ifdef DEBUG_ALLOC
460  if (memory > 500)
461  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p Core Allocate %s %d\n",
462  (void *) pool, apr_pool_tag(pool, NULL), (int) memory);
463  /*switch_assert(memory < 20000); */
464 #endif
465 
466  ptr = apr_palloc(pool, memory);
467  switch_assert(ptr != NULL);
468  memset(ptr, 0, memory);
469 
470 #ifdef LOCK_MORE
471 #ifdef USE_MEM_LOCK
473 #endif
474 #endif
475 
476  return ptr;
477 }
478 
480 {
481 #if !defined(PER_POOL_LOCK) && !defined(INSTANTLY_DESTROY_POOLS)
483  void *pop = NULL;
484  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled memory pool(s)\n",
485  switch_queue_size(memory_manager.pool_recycle_queue) + switch_queue_size(memory_manager.pool_queue));
486 
487  while (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
488  pool = (switch_memory_pool_t *) pop;
489  if (!pool) {
490  break;
491  }
492 #ifdef USE_MEM_LOCK
494 #endif
495  apr_pool_destroy(pool);
496 #ifdef USE_MEM_LOCK
498 #endif
499  }
500 #endif
501  return;
502 }
503 
505 {
506  memory_manager.pool_thread_running = 1;
507 
508  while (memory_manager.pool_thread_running == 1) {
509  int len = switch_queue_size(memory_manager.pool_queue);
510 
511  if (len) {
512  int x = len, done = 0;
513 
514  switch_yield(1000000);
515 #ifdef USE_MEM_LOCK
517 #endif
518  while (x > 0) {
519  void *pop = NULL;
520  if (switch_queue_pop(memory_manager.pool_queue, &pop) != SWITCH_STATUS_SUCCESS || !pop) {
521  done = 1;
522  break;
523  }
524 #if defined(PER_POOL_LOCK) || defined(DESTROY_POOLS)
525 #ifdef USE_MEM_LOCK
527 #endif
528 
529 #ifdef DEBUG_ALLOC
530  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%p DESTROY POOL\n", (void *) pop);
531 #endif
532  apr_pool_destroy(pop);
533 #ifdef USE_MEM_LOCK
535 #endif
536 #else
537  apr_pool_mutex_set(pop, NULL);
538 #ifdef DEBUG_ALLOC
539  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%p DESTROY POOL\n", (void *) pop);
540 #endif
541  apr_pool_clear(pop);
542  if (switch_queue_trypush(memory_manager.pool_recycle_queue, pop) != SWITCH_STATUS_SUCCESS) {
543 #ifdef USE_MEM_LOCK
545 #endif
546 #ifdef DEBUG_ALLOC
547  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%p DESTROY POOL\n", (void *) pop);
548 #endif
549  apr_pool_destroy(pop);
550 #ifdef USE_MEM_LOCK
552 #endif
553 
554  }
555 #endif
556  x--;
557  }
558 #ifdef USE_MEM_LOCK
560 #endif
561  if (done) {
562  goto done;
563  }
564  } else {
565  switch_yield(1000000);
566  }
567  }
568 
569  done:
571 
572  {
573  void *pop = NULL;
574  while (switch_queue_trypop(memory_manager.pool_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
575 #ifdef USE_MEM_LOCK
577 #endif
578  apr_pool_destroy(pop);
579  pop = NULL;
580 #ifdef USE_MEM_LOCK
582 #endif
583 
584  }
585  }
586 
587  memory_manager.pool_thread_running = 0;
588 
589  return NULL;
590 }
591 
592 #ifndef INSTANTLY_DESTROY_POOLS
594 #endif
595 
597 {
598 #ifndef INSTANTLY_DESTROY_POOLS
599  switch_status_t st;
600  void *pop = NULL;
601 
602  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n");
603 
604  memory_manager.pool_thread_running = 0;
606 
607 
608  while (switch_queue_trypop(memory_manager.pool_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
609  apr_pool_destroy(pop);
610  }
611 #endif
612 }
613 
615 {
616 #ifndef INSTANTLY_DESTROY_POOLS
617  switch_threadattr_t *thd_attr;
618 #endif
619 #ifdef PER_POOL_LOCK
620  apr_allocator_t *my_allocator = NULL;
621  apr_thread_mutex_t *my_mutex;
622 #endif
623 
624  memset(&memory_manager, 0, sizeof(memory_manager));
625 
626 #ifdef PER_POOL_LOCK
627  if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) {
628  abort();
629  }
630 
631  if ((apr_pool_create_ex(&memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
632  apr_allocator_destroy(my_allocator);
633  my_allocator = NULL;
634  abort();
635  }
636 
637  if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_NESTED, memory_manager.memory_pool)) != APR_SUCCESS) {
638  abort();
639  }
640 
641  apr_allocator_mutex_set(my_allocator, my_mutex);
642  apr_pool_mutex_set(memory_manager.memory_pool, my_mutex);
643  apr_allocator_owner_set(my_allocator, memory_manager.memory_pool);
644  apr_pool_tag(memory_manager.memory_pool, "core_pool");
645 #else
646  apr_pool_create(&memory_manager.memory_pool, NULL);
647  switch_assert(memory_manager.memory_pool != NULL);
648 #endif
649 
650 #ifdef USE_MEM_LOCK
652 #endif
653 
654 #ifdef INSTANTLY_DESTROY_POOLS
655  {
656  void *foo;
657  foo = (void *) (intptr_t) pool_thread;
658  }
659 #else
660 
661  switch_queue_create(&memory_manager.pool_queue, 50000, memory_manager.memory_pool);
662  switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);
663 
664  switch_threadattr_create(&thd_attr, memory_manager.memory_pool);
665 
667  switch_thread_create(&pool_thread_p, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
668 
669  while (!memory_manager.pool_thread_running) {
671  }
672 #endif
673 
674  return memory_manager.memory_pool;
675 }
676 
677 /* For Emacs:
678  * Local Variables:
679  * mode:c
680  * indent-tabs-mode:t
681  * tab-width:4
682  * c-basic-offset:4
683  * End:
684  * For VIM:
685  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
686  */
struct apr_queue_t switch_queue_t
Definition: switch_apr.h:590
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1114
#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)
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
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:1140
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1119
static switch_thread_t * thread
Definition: switch_log.c:279
switch_memory_pool_t * switch_core_memory_init(void)
switch_queue_t * pool_queue
#define zstr(x)
Definition: switch_utils.h:281
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1255
#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:908
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:285
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:551
static struct @2 memory_manager
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:270
#define SWITCH_BLANK_STRING
Definition: switch_types.h:47
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:638
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)
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)
static switch_thread_t * pool_thread_p
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
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)
struct apr_thread_t switch_thread_t
Definition: switch_apr.h:941
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:1155
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)
Definition: switch_apr.c:1129
struct apr_pool_t switch_memory_pool_t
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:642
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:675
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1109
switch_queue_t * pool_recycle_queue
void switch_core_memory_reclaim(void)
#define switch_assert(expr)
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)