Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vcos_mempool.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /*=============================================================================
  26. VideoCore OS Abstraction Layer - memory pool support
  27. =============================================================================*/
  28. #ifndef VCOS_MEMPOOL_H
  29. #define VCOS_MEMPOOL_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #include "vcos_types.h"
  34. #include "pthreads/vcos_platform.h"
  35. /** \file
  36. *
  37. * Memory pools - variable sized allocator.
  38. *
  39. * A very basic memory pool API.
  40. *
  41. * This interface is deliberately not thread safe - clients should add
  42. * their own locking, if required.
  43. *
  44. *
  45. * \fixme: Add fixed-size allocator.
  46. *
  47. */
  48. /** Initialize a memory pool. The control data is taken from the memory
  49. * supplied itself.
  50. *
  51. * Note: the dmalloc pool uses the memory supplied for its control
  52. * area. This is probably a bit broken, as it stops you creating
  53. * a pool in some "special" area of memory, while leaving the control
  54. * information in normal memory.
  55. *
  56. * @param pool Pointer to pool object.
  57. *
  58. * @param name Name for the pool. Used for diagnostics.
  59. *
  60. * @param start Starting address. Must be at least 8byte aligned.
  61. *
  62. * @param size Size of pool in bytes.
  63. *
  64. * @return VCOS_SUCCESS if pool was created.
  65. */
  66. VCOS_INLINE_DECL
  67. VCOS_STATUS_T vcos_mempool_create(VCOS_MEMPOOL_T *pool, const char *name, void *start, VCOS_UNSIGNED size);
  68. /** Allocate some memory from a pool. If no memory is available, it
  69. * returns NULL.
  70. *
  71. * @param pool Pool to allocate from
  72. * @param len Length of memory to allocate
  73. *
  74. */
  75. VCOS_INLINE_DECL
  76. void *vcos_mempool_alloc(VCOS_MEMPOOL_T *pool, VCOS_UNSIGNED len);
  77. /** Free some memory back to a pool.
  78. *
  79. * @param pool Pool to return to
  80. * @param mem Memory to return
  81. */
  82. VCOS_INLINE_DECL
  83. void vcos_mempool_free(VCOS_MEMPOOL_T *pool, void *mem);
  84. /** Deinitialize a memory pool.
  85. *
  86. * @param pool Pool to return to
  87. */
  88. VCOS_INLINE_DECL
  89. void vcos_mempool_delete(VCOS_MEMPOOL_T *pool);
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #endif