freelist.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright Institute of Communication and Computer Systems (ICCS)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. /**
  18. * \file freelist.h
  19. * \author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * \brief Memory allocation and de-allocation for free-list based raw blocks
  21. */
  22. #ifndef FREELIST_H
  23. #define FREELIST_H
  24. #include <dmmlib/config.h>
  25. #include "dmmlib/freelist/freelist_rb.h"
  26. #ifdef FL_RB_ONLY
  27. /** Tries to allocate memory from a specific free-list organized raw block.
  28. * @param raw_block The pointer of the freelist-organised raw block.
  29. * @param size The requested size.
  30. * @retval The address of the returned memory space.
  31. */
  32. #define dmmlib_malloc(raw_block, size) freelist_malloc(raw_block, size)
  33. /** Frees the memory block inside of a specific free-list organized raw block.
  34. * @param raw_block The pointer of the freelist raw block.
  35. * @param ptr The pointer of the memory block to be freed.
  36. */
  37. #define dmmlib_free(raw_block, ptr) freelist_free(raw_block, ptr)
  38. /**
  39. * Reallocates a memory block from a freelist-organized raw block
  40. *
  41. * @param raw_block The pointer of the freelist raw block.
  42. * @param ptr The pointer of the memory block to be re-allocated.
  43. * @param size The requested memory size.
  44. * @retval The address to serve the request.
  45. * @retval NULL No available memory space.
  46. */
  47. #define dmmlib_realloc(raw_block, ptr, size) freelist_realloc(raw_block, ptr, size)
  48. #endif /* FL_RB_ONLY */
  49. void * freelist_malloc(freelist_rb_t *raw_block, size_t size);
  50. void freelist_free(freelist_rb_t *raw_block, void *ptr);
  51. void * freelist_realloc(freelist_rb_t *raw_block, void *ptr, size_t size);
  52. #ifdef WITH_MEMALIGN
  53. /**
  54. * Tries to allocate memory in an aligned address from a freelist-organized raw
  55. * block.
  56. *
  57. * @param raw_block The pointer of the freelist raw block.
  58. * @param alignment The alignment that you want to use for the memory.
  59. * @param size The requested memory size, in bytes.
  60. * @retval The address to serve the request.
  61. * @retval NULL No available memory space.
  62. */
  63. void * freelist_memalign(freelist_rb_t *raw_block, size_t alignment,
  64. size_t size);
  65. #endif /* WITH_MEMALIGN */
  66. #endif /* FREELIST_H */