shmalloc.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
  3. (c) Copyright 2000-2004 Convergence (integrated media) GmbH
  4. All rights reserved.
  5. Written by Denis Oliver Kropp <dok@directfb.org>,
  6. Andreas Hundt <andi@fischlustig.de>,
  7. Sven Neumann <neo@directfb.org>,
  8. Ville Syrjälä <syrjala@sci.fi> and
  9. Claudio Ciccani <klan@users.sf.net>.
  10. Fusion shmalloc is based on GNU malloc. Please see below.
  11. This library is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU Lesser General Public
  13. License as published by the Free Software Foundation; either
  14. version 2 of the License, or (at your option) any later version.
  15. This library is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. Lesser General Public License for more details.
  19. You should have received a copy of the GNU Lesser General Public
  20. License along with this library; if not, write to the
  21. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. Boston, MA 02111-1307, USA.
  23. */
  24. #ifndef __FUSION__SHMALLOC_H__
  25. #define __FUSION__SHMALLOC_H__
  26. #include <stddef.h>
  27. #include <direct/build.h>
  28. #include <fusion/build.h>
  29. #include <fusion/types.h>
  30. #include <fusion/shm/pool.h>
  31. #if FUSION_BUILD_MULTI && DIRECT_BUILD_TEXT
  32. #define D_OOSHM() (direct_messages_warn( __FUNCTION__, __FUNCTION__, __LINE__, \
  33. "out of shared memory" ), DR_NOSHAREDMEMORY)
  34. #else
  35. #define D_OOSHM() D_OOM()
  36. #endif
  37. void fusion_dbg_print_memleaks( FusionSHMPoolShared *pool );
  38. void *fusion_dbg_shmalloc ( FusionSHMPoolShared *pool,
  39. const char *file, int line,
  40. const char *func, size_t __size );
  41. void *fusion_dbg_shcalloc ( FusionSHMPoolShared *pool,
  42. const char *file, int line,
  43. const char *func, size_t __nmemb, size_t __size);
  44. void *fusion_dbg_shrealloc( FusionSHMPoolShared *pool,
  45. const char *file, int line,
  46. const char *func, const char *what, void *__ptr,
  47. size_t __size );
  48. void fusion_dbg_shfree ( FusionSHMPoolShared *pool,
  49. const char *file, int line,
  50. const char *func, const char *what, void *__ptr );
  51. char *fusion_dbg_shstrdup ( FusionSHMPoolShared *pool,
  52. const char *file, int line,
  53. const char *func, const char *string );
  54. /* Allocate SIZE bytes of memory. */
  55. void *fusion_shmalloc (FusionSHMPoolShared *pool, size_t __size);
  56. /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
  57. void *fusion_shcalloc (FusionSHMPoolShared *pool, size_t __nmemb, size_t __size);
  58. /* Re-allocate the previously allocated block
  59. in __ptr, making the new block SIZE bytes long. */
  60. void *fusion_shrealloc (FusionSHMPoolShared *pool, void *__ptr, size_t __size);
  61. /* Free a block allocated by `shmalloc', `shrealloc' or `shcalloc'. */
  62. void fusion_shfree (FusionSHMPoolShared *pool, void *__ptr);
  63. /* Duplicate string in shared memory. */
  64. char *fusion_shstrdup (FusionSHMPoolShared *pool, const char *string);
  65. #if DIRECT_BUILD_DEBUGS || DIRECT_BUILD_DEBUG || defined(DIRECT_ENABLE_DEBUG) || defined(DIRECT_FORCE_DEBUG)
  66. #if !DIRECT_BUILD_DEBUGS
  67. #warning Building with debug, but library headers suggest that debug is not supported.
  68. #endif
  69. #define SHMALLOC(pool,bytes) fusion_dbg_shmalloc( pool, __FUNCTION__, __LINE__, __FUNCTION__, bytes )
  70. #define SHCALLOC(pool,count,bytes) fusion_dbg_shcalloc( pool, __FUNCTION__, __LINE__, __FUNCTION__, count, bytes )
  71. #define SHREALLOC(pool,mem,bytes) fusion_dbg_shrealloc( pool, __FUNCTION__, __LINE__, __FUNCTION__, #mem, mem, bytes )
  72. #define SHFREE(pool,mem) fusion_dbg_shfree( pool, __FUNCTION__, __LINE__, __FUNCTION__, #mem,mem )
  73. #define SHSTRDUP(pool,string) fusion_dbg_shstrdup( pool, __FUNCTION__, __LINE__, __FUNCTION__, string )
  74. #else
  75. #define SHMALLOC fusion_shmalloc
  76. #define SHCALLOC fusion_shcalloc
  77. #define SHREALLOC fusion_shrealloc
  78. #define SHFREE fusion_shfree
  79. #define SHSTRDUP fusion_shstrdup
  80. #endif
  81. #endif