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.

91 lines
2.7KB

  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-2016 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. * Destroy previously created memory pool
  51. *
  52. * <b>may/will sleep</b>
  53. */
  54. void rtsafe_memory_pool_destroy(RtMemPool_Handle handle);
  55. /**
  56. * Allocate memory in context where sleeping is not allowed
  57. *
  58. * <b>will not sleep</b>
  59. *
  60. * @return Pointer to allocated memory or NULL if memory no memory is available
  61. */
  62. void* rtsafe_memory_pool_allocate_atomic(RtMemPool_Handle handle);
  63. /**
  64. * Allocate memory in context where sleeping is allowed
  65. *
  66. * <b>may/will sleep</b>
  67. *
  68. * @return Pointer to allocated memory or NULL if memory no memory is available (should not happen under normal conditions)
  69. */
  70. void* rtsafe_memory_pool_allocate_sleepy(RtMemPool_Handle handle);
  71. /**
  72. * Deallocate previously allocated memory
  73. *
  74. * <b>will not sleep</b>
  75. *
  76. * @param memoryPtr pointer to previously allocated memory chunk
  77. */
  78. void rtsafe_memory_pool_deallocate(RtMemPool_Handle handle,
  79. void* memoryPtr);
  80. #endif // __RTMEMPOOL_H__