mem.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 Fhg Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include <stdio.h>
  28. #include "../config.h"
  29. #include "../dprint.h"
  30. #include "../globals.h"
  31. #include "mem.h"
  32. #ifdef PKG_MALLOC
  33. #ifdef VQ_MALLOC
  34. #include "vq_malloc.h"
  35. #else
  36. #include "q_malloc.h"
  37. #endif
  38. #endif
  39. #ifdef SHM_MEM
  40. #include "shm_mem.h"
  41. #endif
  42. #ifdef PKG_MALLOC
  43. char mem_pool[PKG_MEM_POOL_SIZE];
  44. #ifdef VQ_MALLOC
  45. struct vqm_block* mem_block;
  46. #elif defined F_MALLOC
  47. struct fm_block* mem_block;
  48. #else
  49. struct qm_block* mem_block;
  50. #endif
  51. #endif
  52. int init_mallocs()
  53. {
  54. #ifdef PKG_MALLOC
  55. /*init mem*/
  56. #ifdef VQ_MALLOC
  57. mem_block=vqm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
  58. #elif F_MALLOC
  59. mem_block=fm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
  60. #else
  61. mem_block=qm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
  62. #endif
  63. if (mem_block==0){
  64. LOG(L_CRIT, "could not initialize memory pool\n");
  65. fprintf(stderr, "Too much pkg memory demanded: %d\n",
  66. PKG_MEM_POOL_SIZE );
  67. return -1;
  68. }
  69. #endif
  70. #ifdef SHM_MEM
  71. if (shm_mem_init()<0) {
  72. LOG(L_CRIT, "could not initialize shared memory pool, exiting...\n");
  73. fprintf(stderr, "Too much shared memory demanded: %d\n",
  74. shm_mem_size );
  75. return -1;
  76. }
  77. #endif
  78. return 0;
  79. }