mem.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* $Id$
  2. *
  3. * memory related stuff (malloc & friends)
  4. *
  5. *
  6. * Copyright (C) 2001-2003 Fhg Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. */
  29. #ifndef mem_h
  30. #define mem_h
  31. #include "../config.h"
  32. #include "../dprint.h"
  33. #ifdef PKG_MALLOC
  34. # ifdef VQ_MALLOC
  35. # include "vq_malloc.h"
  36. extern struct vqm_block* mem_block;
  37. # elif defined F_MALLOC
  38. # include "f_malloc.h"
  39. extern struct fm_block* mem_block;
  40. # else
  41. # include "q_malloc.h"
  42. extern struct qm_block* mem_block;
  43. # endif
  44. extern char mem_pool[PKG_MEM_POOL_SIZE];
  45. # ifdef DBG_QM_MALLOC
  46. # ifdef VQ_MALLOC
  47. # define pkg_malloc(s) vqm_malloc(mem_block, (s),__FILE__, \
  48. __FUNCTION__, __LINE__)
  49. # define pkg_free(p) vqm_free(mem_block, (p), __FILE__, \
  50. __FUNCTION__, __LINE__)
  51. # elif defined F_MALLOC
  52. # define pkg_malloc(s) fm_malloc(mem_block, (s),__FILE__, \
  53. __FUNCTION__, __LINE__);
  54. # define pkg_free(p) fm_free(mem_block, (p), __FILE__, \
  55. __FUNCTION__, __LINE__);
  56. # else
  57. # define pkg_malloc(s) qm_malloc(mem_block, (s),__FILE__, \
  58. __FUNCTION__, __LINE__);
  59. # define pkg_free(p) qm_free(mem_block, (p), __FILE__, \
  60. __FUNCTION__, __LINE__);
  61. # endif
  62. # else
  63. # ifdef VQ_MALLOC
  64. # define pkg_malloc(s) vqm_malloc(mem_block, (s))
  65. # define pkg_free(p) vqm_free(mem_block, (p))
  66. # elif defined F_MALLOC
  67. # define pkg_malloc(s) fm_malloc(mem_block, (s))
  68. # define pkg_free(p) fm_free(mem_block, (p))
  69. # else
  70. # define pkg_malloc(s) qm_malloc(mem_block, (s))
  71. # define pkg_free(p) qm_free(mem_block, (p))
  72. # endif
  73. # endif
  74. # ifdef VQ_MALLOC
  75. # define pkg_status() vqm_status(mem_block)
  76. # elif defined F_MALLOC
  77. # define pkg_status() fm_status(mem_block)
  78. # else
  79. # define pkg_status() qm_status(mem_block)
  80. # endif
  81. #elif defined(SHM_MEM) && defined(USE_SHM_MEM)
  82. # include "shm_mem.h"
  83. # define pkg_malloc(s) shm_malloc((s))
  84. # define pkg_free(p) shm_free((p))
  85. # define pkg_status() shm_status()
  86. #else
  87. # include <stdlib.h>
  88. # define pkg_malloc(s) \
  89. ( { void *v; v=malloc((s)); \
  90. DBG("malloc %x size %d end %x\n", v, s, (unsigned int)v+(s));\
  91. v; } )
  92. # define pkg_free(p) do{ DBG("free %x\n", (p)); free((p)); }while(0);
  93. # define pkg_status()
  94. #endif
  95. int init_mallocs();
  96. #endif