/media/libvpx/vpx_mem/vpx_mem.h

http://github.com/zpao/v8monkey · C Header · 179 lines · 120 code · 26 blank · 33 comment · 0 complexity · fe2aa1ece735589a5d42944e8c8b4156 MD5 · raw file

  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef __VPX_MEM_H__
  11. #define __VPX_MEM_H__
  12. #if defined(__uClinux__)
  13. # include <lddk.h>
  14. #endif
  15. /* vpx_mem version info */
  16. #define vpx_mem_version "2.2.1.5"
  17. #define VPX_MEM_VERSION_CHIEF 2
  18. #define VPX_MEM_VERSION_MAJOR 2
  19. #define VPX_MEM_VERSION_MINOR 1
  20. #define VPX_MEM_VERSION_PATCH 5
  21. /* end - vpx_mem version info */
  22. #ifndef VPX_TRACK_MEM_USAGE
  23. # define VPX_TRACK_MEM_USAGE 0 /* enable memory tracking/integrity checks */
  24. #endif
  25. #ifndef VPX_CHECK_MEM_FUNCTIONS
  26. # define VPX_CHECK_MEM_FUNCTIONS 0 /* enable basic safety checks in _memcpy,
  27. _memset, and _memmove */
  28. #endif
  29. #ifndef REPLACE_BUILTIN_FUNCTIONS
  30. # define REPLACE_BUILTIN_FUNCTIONS 0 /* replace builtin functions with their
  31. vpx_ equivalents */
  32. #endif
  33. #include <stdlib.h>
  34. #include <stddef.h>
  35. #if defined(__cplusplus)
  36. extern "C" {
  37. #endif
  38. /*
  39. vpx_mem_get_version()
  40. provided for runtime version checking. Returns an unsigned int of the form
  41. CHIEF | MAJOR | MINOR | PATCH, where the chief version number is the high
  42. order byte.
  43. */
  44. unsigned int vpx_mem_get_version(void);
  45. /*
  46. vpx_mem_set_heap_size(size_t size)
  47. size - size in bytes for the memory manager to allocate for its heap
  48. Sets the memory manager's initial heap size
  49. Return:
  50. 0: on success
  51. -1: if memory manager calls have not been included in the vpx_mem lib
  52. -2: if the memory manager has been compiled to use static memory
  53. -3: if the memory manager has already allocated its heap
  54. */
  55. int vpx_mem_set_heap_size(size_t size);
  56. void *vpx_memalign(size_t align, size_t size);
  57. void *vpx_malloc(size_t size);
  58. void *vpx_calloc(size_t num, size_t size);
  59. void *vpx_realloc(void *memblk, size_t size);
  60. void vpx_free(void *memblk);
  61. void *vpx_memcpy(void *dest, const void *src, size_t length);
  62. void *vpx_memset(void *dest, int val, size_t length);
  63. void *vpx_memmove(void *dest, const void *src, size_t count);
  64. /* special memory functions */
  65. void *vpx_mem_alloc(int id, size_t size, size_t align);
  66. void vpx_mem_free(int id, void *mem, size_t size);
  67. /* Wrappers to standard library functions. */
  68. typedef void*(* g_malloc_func)(size_t);
  69. typedef void*(* g_calloc_func)(size_t, size_t);
  70. typedef void*(* g_realloc_func)(void *, size_t);
  71. typedef void (* g_free_func)(void *);
  72. typedef void*(* g_memcpy_func)(void *, const void *, size_t);
  73. typedef void*(* g_memset_func)(void *, int, size_t);
  74. typedef void*(* g_memmove_func)(void *, const void *, size_t);
  75. int vpx_mem_set_functions(g_malloc_func g_malloc_l
  76. , g_calloc_func g_calloc_l
  77. , g_realloc_func g_realloc_l
  78. , g_free_func g_free_l
  79. , g_memcpy_func g_memcpy_l
  80. , g_memset_func g_memset_l
  81. , g_memmove_func g_memmove_l);
  82. int vpx_mem_unset_functions(void);
  83. /* some defines for backward compatibility */
  84. #define DMEM_GENERAL 0
  85. #define duck_memalign(X,Y,Z) vpx_memalign(X,Y)
  86. #define duck_malloc(X,Y) vpx_malloc(X)
  87. #define duck_calloc(X,Y,Z) vpx_calloc(X,Y)
  88. #define duck_realloc vpx_realloc
  89. #define duck_free vpx_free
  90. #define duck_memcpy vpx_memcpy
  91. #define duck_memmove vpx_memmove
  92. #define duck_memset vpx_memset
  93. #if REPLACE_BUILTIN_FUNCTIONS
  94. # ifndef __VPX_MEM_C__
  95. # define memalign vpx_memalign
  96. # define malloc vpx_malloc
  97. # define calloc vpx_calloc
  98. # define realloc vpx_realloc
  99. # define free vpx_free
  100. # define memcpy vpx_memcpy
  101. # define memmove vpx_memmove
  102. # define memset vpx_memset
  103. # endif
  104. #endif
  105. #if CONFIG_MEM_TRACKER
  106. #include <stdarg.h>
  107. /*from vpx_mem/vpx_mem_tracker.c*/
  108. extern void vpx_memory_tracker_dump();
  109. extern void vpx_memory_tracker_check_integrity(char *file, unsigned int line);
  110. extern int vpx_memory_tracker_set_log_type(int type, char *option);
  111. extern int vpx_memory_tracker_set_log_func(void *userdata,
  112. void(*logfunc)(void *userdata,
  113. const char *fmt, va_list args));
  114. # ifndef __VPX_MEM_C__
  115. # define vpx_memalign(align, size) xvpx_memalign((align), (size), __FILE__, __LINE__)
  116. # define vpx_malloc(size) xvpx_malloc((size), __FILE__, __LINE__)
  117. # define vpx_calloc(num, size) xvpx_calloc(num, size, __FILE__, __LINE__)
  118. # define vpx_realloc(addr, size) xvpx_realloc(addr, size, __FILE__, __LINE__)
  119. # define vpx_free(addr) xvpx_free(addr, __FILE__, __LINE__)
  120. # define vpx_memory_tracker_check_integrity() vpx_memory_tracker_check_integrity(__FILE__, __LINE__)
  121. # define vpx_mem_alloc(id,size,align) xvpx_mem_alloc(id, size, align, __FILE__, __LINE__)
  122. # define vpx_mem_free(id,mem,size) xvpx_mem_free(id, mem, size, __FILE__, __LINE__)
  123. # endif
  124. void *xvpx_memalign(size_t align, size_t size, char *file, int line);
  125. void *xvpx_malloc(size_t size, char *file, int line);
  126. void *xvpx_calloc(size_t num, size_t size, char *file, int line);
  127. void *xvpx_realloc(void *memblk, size_t size, char *file, int line);
  128. void xvpx_free(void *memblk, char *file, int line);
  129. void *xvpx_mem_alloc(int id, size_t size, size_t align, char *file, int line);
  130. void xvpx_mem_free(int id, void *mem, size_t size, char *file, int line);
  131. #else
  132. # ifndef __VPX_MEM_C__
  133. # define vpx_memory_tracker_dump()
  134. # define vpx_memory_tracker_check_integrity()
  135. # define vpx_memory_tracker_set_log_type(t,o) 0
  136. # define vpx_memory_tracker_set_log_func(u,f) 0
  137. # endif
  138. #endif
  139. #if !VPX_CHECK_MEM_FUNCTIONS
  140. # ifndef __VPX_MEM_C__
  141. # include <string.h>
  142. # define vpx_memcpy memcpy
  143. # define vpx_memset memset
  144. # define vpx_memmove memmove
  145. # endif
  146. #endif
  147. #ifdef VPX_MEM_PLTFRM
  148. # include VPX_MEM_PLTFRM
  149. #endif
  150. #if defined(__cplusplus)
  151. }
  152. #endif
  153. #endif /* __VPX_MEM_H__ */