Audio plugin host https://kx.studio/carla
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.

109 lines
3.3KB

  1. /*
  2. * RealTime Memory Pool, heavily based on work by Nedko Arnaudov
  3. * Copyright (C) 2006-2009 Nedko Arnaudov <nedko@arnaudov.name>
  4. * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * For a full copy of the GNU General Public License see the GPL.txt file
  17. */
  18. #ifndef __RTMEMPOOL_H__
  19. #define __RTMEMPOOL_H__
  20. #ifdef __cplusplus
  21. # include <cstddef>
  22. #else
  23. # include <stdbool.h>
  24. # include <stddef.h>
  25. #endif
  26. /** max size of memory pool name, in chars, including terminating zero char */
  27. #define RTSAFE_MEMORY_POOL_NAME_MAX 128
  28. /**
  29. * Opaque data for RtMemPool_Pool.
  30. */
  31. typedef void* RtMemPool_Handle;
  32. /**
  33. * Create new memory pool
  34. *
  35. * <b>may/will sleep</b>
  36. *
  37. * @param poolName pool name, for debug purposes, max RTSAFE_MEMORY_POOL_NAME_MAX chars, including terminating zero char. May be NULL.
  38. * @param dataSize memory chunk size
  39. * @param minPreallocated min chunks preallocated
  40. * @param maxPreallocated max chunks preallocated
  41. *
  42. * @return Success status, true if successful
  43. */
  44. bool rtsafe_memory_pool_create(RtMemPool_Handle* handlePtr,
  45. const char* poolName,
  46. size_t dataSize,
  47. size_t minPreallocated,
  48. size_t maxPreallocated);
  49. /**
  50. * Create new memory pool, thread-safe version
  51. *
  52. * <b>may/will sleep</b>
  53. *
  54. * @param poolName pool name, for debug purposes, max RTSAFE_MEMORY_POOL_NAME_MAX chars, including terminating zero char. May be NULL.
  55. * @param dataSize memory chunk size
  56. * @param minPreallocated min chunks preallocated
  57. * @param maxPreallocated max chunks preallocated
  58. *
  59. * @return Success status, true if successful
  60. */
  61. bool rtsafe_memory_pool_create_safe(RtMemPool_Handle* handlePtr,
  62. const char* poolName,
  63. size_t dataSize,
  64. size_t minPreallocated,
  65. size_t maxPreallocated);
  66. /**
  67. * Destroy previously created memory pool
  68. *
  69. * <b>may/will sleep</b>
  70. */
  71. void rtsafe_memory_pool_destroy(RtMemPool_Handle handle);
  72. /**
  73. * Allocate memory in context where sleeping is not allowed
  74. *
  75. * <b>will not sleep</b>
  76. *
  77. * @return Pointer to allocated memory or NULL if memory no memory is available
  78. */
  79. void* rtsafe_memory_pool_allocate_atomic(RtMemPool_Handle handle);
  80. /**
  81. * Allocate memory in context where sleeping is allowed
  82. *
  83. * <b>may/will sleep</b>
  84. *
  85. * @return Pointer to allocated memory or NULL if memory no memory is available (should not happen under normal conditions)
  86. */
  87. void* rtsafe_memory_pool_allocate_sleepy(RtMemPool_Handle handle);
  88. /**
  89. * Deallocate previously allocated memory
  90. *
  91. * <b>will not sleep</b>
  92. *
  93. * @param memoryPtr pointer to previously allocated memory chunk
  94. */
  95. void rtsafe_memory_pool_deallocate(RtMemPool_Handle handle,
  96. void* memoryPtr);
  97. #endif // __RTMEMPOOL_H__