LV2 Extensions
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.

111 lines
3.5KB

  1. /*
  2. LV2 realtime safe memory pool extension definition
  3. Copyright 2020 Filipe Coelho <falktx@falktx.com>
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted, provided that the above
  6. copyright notice and this permission notice appear in all copies.
  7. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. /**
  16. * @file lv2_rtmempool.h
  17. * C header for the LV2 rtmempool extension <http://kxstudio.sf.net/ns/lv2ext/rtmempool>.
  18. *
  19. */
  20. #ifndef LV2_RTMEMPOOL_H
  21. #define LV2_RTMEMPOOL_H
  22. #define LV2_RTSAFE_MEMORY_POOL_URI "http://kxstudio.sf.net/ns/lv2ext/rtmempool"
  23. #define LV2_RTSAFE_MEMORY_POOL_PREFIX LV2_RTSAFE_MEMORY_POOL_URI "#"
  24. #define LV2_RTSAFE_MEMORY_POOL__Pool LV2_RTSAFE_MEMORY_POOL_URI "Pool"
  25. /** max size of memory pool name, in chars, including terminating zero char */
  26. #define LV2_RTSAFE_MEMORY_POOL_NAME_MAX 128
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #else
  30. #include <stdbool.h>
  31. #endif
  32. /**
  33. * Opaque data to host data for LV2_RtMemPool_Pool.
  34. */
  35. typedef void* LV2_RtMemPool_Handle;
  36. /**
  37. * On instantiation, host must supply LV2_RTSAFE_MEMORY_POOL__Pool feature.
  38. * LV2_Feature::data must be pointer to LV2_RtMemPool_Pool.
  39. */
  40. typedef struct _LV2_RtMemPool_Pool {
  41. /**
  42. * This function is called when plugin wants to create memory pool
  43. *
  44. * <b>may/will sleep</b>
  45. *
  46. * @param pool_name pool name, for debug purposes, max RTSAFE_MEMORY_POOL_NAME_MAX chars, including terminating zero char. May be NULL.
  47. * @param data_size memory chunk size
  48. * @param min_preallocated min chunks preallocated
  49. * @param max_preallocated max chunks preallocated
  50. *
  51. * @return Success status, true if successful
  52. */
  53. bool (*create)(LV2_RtMemPool_Handle * handle_ptr,
  54. const char * pool_name,
  55. size_t data_size,
  56. size_t min_preallocated,
  57. size_t max_preallocated);
  58. /**
  59. * This function is called when plugin wants to destroy previously created memory pool
  60. *
  61. * <b>may/will sleep</b>
  62. */
  63. void (*destroy)(LV2_RtMemPool_Handle handle);
  64. /**
  65. * This function is called when plugin wants to allocate memory in context where sleeping is not allowed
  66. *
  67. * <b>will not sleep</b>
  68. *
  69. * @return Pointer to allocated memory or NULL if memory no memory is available
  70. */
  71. void * (*allocate_atomic)(LV2_RtMemPool_Handle handle);
  72. /**
  73. * This function is called when plugin wants to allocate memory in context where sleeping is allowed
  74. *
  75. * <b>may/will sleep</b>
  76. *
  77. * @return Pointer to allocated memory or NULL if memory no memory is available (should not happen under normal conditions)
  78. */
  79. void * (*allocate_sleepy)(LV2_RtMemPool_Handle handle);
  80. /**
  81. * This function is called when plugin wants to deallocate previously allocated memory
  82. *
  83. * <b>will not sleep</b>
  84. *
  85. * @param memory_ptr pointer to previously allocated memory chunk
  86. */
  87. void (*deallocate)(LV2_RtMemPool_Handle handle,
  88. void * memory_ptr);
  89. } LV2_RtMemPool_Pool;
  90. #ifdef __cplusplus
  91. } /* extern "C" */
  92. #endif
  93. #endif /* LV2_RTMEMPOOL_H */