123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- /*
- * Copyright (C) 2005 iptelorg GmbH
- *
- * This file is part of ser, a free SIP server.
- *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- * [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
- #ifndef __CDS_MEMORY_H
- #define __CDS_MEMORY_H
- /* #define TRACE_CDS_MEMORY */
- #ifdef __cplusplus
- extern "C" {
- #endif
- /** \ingroup cds
- * @{
- *
- * \defgroup cds_memory Memory management
- *
- * Memory operations are common for whole CDS library. Because it must work
- together with SER's memory management and must work without it too, there are
- wrapper macros for memory allocation/deallocation.
- *
- * @{ */
- /* typedef void*(*cds_malloc_func)(unsigned int size);
- typedef void(*cds_free_func)(void *ptr);
- extern cds_malloc_func cds_malloc;
- extern cds_free_func cds_free;
- void cds_set_memory_functions(cds_malloc_func _malloc, cds_free_func _free); */
- /** \def cds_malloc(s)
- * Function/macro for memory allocation. Which function is choosen depends on
- * SER and TRACE_CDS_MEMORY defines.
- *
- * When SER is defined shm_malloc is choosen, standard malloc otherwise. */
- /** \def cds_free(p)
- * Function/macro for memory deallocation. Which function is choosen depends
- * on SER and TRACE_CDS_MEMORY defines.
- *
- * If SER is defined shm_free is choosen, standard free otherwise. */
- /** \def cds_malloc_ptr
- * Function/macro for memory allocation when pointer to function needed. Which
- * function is choosen depends on SER and TRACE_CDS_MEMORY defines.
- *
- * If SER is defined shm_malloc is choosen, standard malloc otherwise. */
- /** \def cds_free_ptr
- * Function/macro for memory deallocation when pointer to function needed.
- * Which function is choosen depends on SER and TRACE_CDS_MEMORY defines.
- *
- * If SER is defined shm_free is choosen, standard free otherwise. */
- /** \def cds_malloc_pkg(s)
- * Function/macro for 'local' memory allocation. Which function is choosen
- * depends on SER and TRACE_CDS_MEMORY defines.
- *
- * When SER is defined pkg_malloc is choosen, standard malloc otherwise. */
- /** \def cds_free_pkg(p)
- * Function/macro for 'local' memory deallocation. Which function is choosen
- * depends on SER and TRACE_CDS_MEMORY defines.
- *
- * When SER is defined pkg_free is choosen, standard free otherwise. */
- #ifdef TRACE_CDS_MEMORY
- /** \internal Debugging variant of alloc function */
- void *debug_malloc(int size, const char *file, int line);
- /** \internal Debugging variant of free function */
- void debug_free(void *block, const char *file, int line);
- /** \internal Another debugging variant of alloc function - used when pointer
- * to function needed. */
- void *debug_malloc_ex(unsigned int size);
- /** \internal Another debugging variant of free function - used when pointer to
- * function needed. */
- void debug_free_ex(void *block);
- /* \internal Helper function for debugging - shows some debugging information about
- * memory allocations (currently only the number of allocated blocks). */
- void cds_memory_trace(char *dst, int dst_len);
- /** \internal Helper function which is useful for memory debugging only - initializes
- * internal variables for memory tracing */
- void cds_memory_trace_init();
- #define cds_malloc(s) debug_malloc(s,__FILE__, __LINE__)
- #define cds_free(p) debug_free(p,__FILE__, __LINE__)
- #define cds_free_ptr debug_free_ex
- #define cds_malloc_ptr debug_malloc_ex
- #define cds_malloc_pkg(s) debug_malloc(s,__FILE__, __LINE__)
- #define cds_free_pkg(p) debug_free(p,__FILE__, __LINE__)
- #else /* !TRACE */
- #ifdef SER
- #include <mem/mem.h>
- #include <mem/shm_mem.h>
- void* shm_malloc_x(unsigned int size);
- void shm_free_x(void *ptr);
- #define cds_malloc(s) shm_malloc(s)
- #define cds_free(p) shm_free(p)
- #define cds_malloc_ptr shm_malloc_x
- #define cds_free_ptr shm_free_x
- #define cds_malloc_pkg(s) pkg_malloc(s)
- #define cds_free_pkg(p) pkg_free(p)
- #else /* !SER */
- #include <stdlib.h>
- #define cds_malloc(s) malloc(s)
- #define cds_free(p) free(p)
- #define cds_malloc_ptr malloc
- #define cds_free_ptr free
- #define cds_malloc_pkg(s) malloc(s)
- #define cds_free_pkg(p) free(p)
- #endif /* !SER */
- #endif /* !TRACE_CDS_MEMORY */
- #ifdef __cplusplus
- }
- #endif
- /** @}
- * @} */
- #endif
|