block_header_funcs.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright 2012 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 block_header_funcs.h
  19. * \author Ioannis Koutras (joko@microlab.ntua.gr)
  20. *
  21. * \brief Memory block functions.
  22. */
  23. #ifndef BLOCK_HEADER_FUNCS_H
  24. #define BLOCK_HEADER_FUNCS_H
  25. #include "dmmlib/freelist/block_header.h"
  26. #include "dmmlib/freelist/freelist_rb.h"
  27. /**
  28. * \brief Get the address of the block header of a memory block.
  29. *
  30. * \param ptr The data part of the memory block.
  31. */
  32. block_header_t * get_header(void *ptr);
  33. /**
  34. * Get the size of the memory block's data
  35. *
  36. * \param ptr The pointer to the current memory block.
  37. *
  38. * \return The size of the data part of the current memory block.
  39. */
  40. size_t get_size(block_header_t *ptr);
  41. #ifdef REQUEST_SIZE_INFO
  42. /** Macro to set the requested size to the header of a free-list's memory
  43. * block */
  44. #define SET_REQUESTED_SIZE(ptr, size) set_requested_size(ptr, size)
  45. /**
  46. * Set the requested size of memory block's data
  47. *
  48. * \param ptr The pointer to the data part of the current memory block.
  49. * \param size The requested size for the data part of the current memory
  50. * block.
  51. */
  52. void set_requested_size(block_header_t *ptr, size_t size);
  53. /**
  54. * Get the requested size of the memory block's data
  55. *
  56. * \param ptr The pointer to the data part of the current memory block.
  57. *
  58. * \return The size of the data that was initialy requested for this memory
  59. * block.
  60. */
  61. size_t get_requested_size(block_header_t *ptr);
  62. #else /* REQUEST_SIZE_INFO */
  63. /** Does nothing */
  64. #define SET_REQUESTED_SIZE(...)
  65. #endif /* REQUEST_SIZE_INFO */
  66. /**
  67. * Get all information of the memory block header's size record
  68. *
  69. * \param ptr The pointer to the data part of the current memory block.
  70. *
  71. * \return The availability and the size of the data part of the current memory
  72. * block.
  73. */
  74. size_t get_size_availability(block_header_t *ptr);
  75. /**
  76. * Set the size of the memory block's data and mark it free
  77. *
  78. * \param raw_block The pointer to the raw block which includes the block.
  79. * \param ptr The pointer to the data part of the current memory block.
  80. * \param size The size of the data part of the current memory block.
  81. */
  82. void set_size_and_free(freelist_rb_t *raw_block, block_header_t *ptr, size_t size);
  83. /**
  84. * Set the size of the memory block's data and mark it used
  85. *
  86. * \param raw_block The pointer to the raw block which includes the block.
  87. * \param ptr The pointer to the data part of the current memory block.
  88. * \param size The size of the data part of the current memory block.
  89. */
  90. void set_size_and_used(freelist_rb_t *raw_block, block_header_t *ptr, size_t size);
  91. /**
  92. * Mark the memory block as used, as well as the previous_size element of the
  93. * next block if there is one.
  94. *
  95. * \param raw_block The pointer to the raw block which includes the block.
  96. * \param ptr The pointer to the data part of the memory block.
  97. */
  98. void mark_used(freelist_rb_t *raw_block, block_header_t *ptr);
  99. /**
  100. * Mark the memory block as free, as well as the previous_size element of the
  101. * next block if there is one.
  102. *
  103. * \param raw_block The pointer to the raw block which includes the block.
  104. * \param ptr The pointer to the data part of the memory block.
  105. */
  106. void mark_free(freelist_rb_t *raw_block, block_header_t *ptr);
  107. /**
  108. * Set the availability and the size of the previous memory block
  109. *
  110. * \param ptr The pointer to the data part of the previous memory block.
  111. * \param previous_size_availability The size for the data part of the previous
  112. * memory block on data layout level.
  113. */
  114. void set_previous_size_availability(block_header_t *ptr, size_t previous_size_availability);
  115. /**
  116. * Check if a memory block is free
  117. */
  118. bool is_free(block_header_t *ptr);
  119. /**
  120. * Check if previous block (in the memory space) belongs to a free list
  121. */
  122. bool is_previous_free(block_header_t *ptr);
  123. /**
  124. * Get the size of the previous block (in the memory space)
  125. *
  126. * \param ptr The pointer to the data part of the current memory block.
  127. */
  128. size_t get_previous_size(block_header_t *ptr);
  129. /**
  130. * Get the size and the availability of the previous block (in the memory
  131. * space)
  132. *
  133. * \param ptr The pointer to the data part of the previous memory block.
  134. */
  135. size_t get_previous_size_availability(block_header_t *ptr);
  136. /**
  137. * Get the previous memory block on data layout level
  138. *
  139. * \param ptr The pointer to the data part of the current memory block.
  140. *
  141. * \return The pointer to the data part of the previous memory block on
  142. * data layout level.
  143. */
  144. block_header_t * get_dlprevious(block_header_t *ptr);
  145. /**
  146. * Get the next memory block on data layout level if there is one
  147. *
  148. * \param raw_block The pointer to the raw block which includes the block.
  149. * \param ptr The pointer to the data part of the current memory block.
  150. *
  151. * \return The pointer to the data part of the next block.
  152. * \retval NULL There is no next block.
  153. */
  154. block_header_t * get_dlnext(freelist_rb_t *raw_block, block_header_t *ptr);
  155. #endif /* BLOCK_HEADER_FUNCS_H */