block_header_funcs.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "freelist/block_header.h"
  26. #include "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. /**
  43. * Set the requested size of memory block's data
  44. *
  45. * \param ptr The pointer to the data part of the current memory block.
  46. * \param size The requested size for the data part of the current memory
  47. * block.
  48. */
  49. void set_requested_size(block_header_t *ptr, size_t size);
  50. /**
  51. * Get the requested size of the memory block's data
  52. *
  53. * \param ptr The pointer to the data part of the current memory block.
  54. *
  55. * \return The size of the data that was initialy requested for this memory
  56. * block.
  57. */
  58. size_t get_requested_size(block_header_t *ptr);
  59. #endif /* REQUEST_SIZE_INFO */
  60. /**
  61. * Get all information of the memory block header's size record
  62. *
  63. * \param ptr The pointer to the data part of the current memory block.
  64. *
  65. * \return The availability and the size of the data part of the current memory
  66. * block.
  67. */
  68. size_t get_size_availability(block_header_t *ptr);
  69. /**
  70. * Set the size of the memory block's data and mark it free
  71. *
  72. * \param raw_block The pointer to the raw block which includes the block.
  73. * \param ptr The pointer to the data part of the current memory block.
  74. * \param size The size of the data part of the current memory block.
  75. */
  76. void set_size_and_free(freelist_rb_t *raw_block, block_header_t *ptr, size_t size);
  77. /**
  78. * Set the size of the memory block's data and mark it used
  79. *
  80. * \param raw_block The pointer to the raw block which includes the block.
  81. * \param ptr The pointer to the data part of the current memory block.
  82. * \param size The size of the data part of the current memory block.
  83. */
  84. void set_size_and_used(freelist_rb_t *raw_block, block_header_t *ptr, size_t size);
  85. /**
  86. * Mark the memory block as used, as well as the previous_size element of the
  87. * next block if there is one.
  88. *
  89. * \param raw_block The pointer to the raw block which includes the block.
  90. * \param ptr The pointer to the data part of the memory block.
  91. */
  92. void mark_used(freelist_rb_t *raw_block, block_header_t *ptr);
  93. /**
  94. * Mark the memory block as free, as well as the previous_size element of the
  95. * next block if there is one.
  96. *
  97. * \param raw_block The pointer to the raw block which includes the block.
  98. * \param ptr The pointer to the data part of the memory block.
  99. */
  100. void mark_free(freelist_rb_t *raw_block, block_header_t *ptr);
  101. /**
  102. * Set the availability and the size of the previous memory block
  103. *
  104. * \param ptr The pointer to the data part of the previous memory block.
  105. * \param previous_size_availability The size for the data part of the previous
  106. * memory block on data layout level.
  107. */
  108. void set_previous_size_availability(block_header_t *ptr, size_t previous_size_availability);
  109. /**
  110. * Check if a memory block is free
  111. */
  112. bool is_free(block_header_t *ptr);
  113. /**
  114. * Check if previous block (in the memory space) belongs to a free list
  115. */
  116. bool is_previous_free(block_header_t *ptr);
  117. /**
  118. * Get the size of the previous block (in the memory space)
  119. *
  120. * \param ptr The pointer to the data part of the current memory block.
  121. */
  122. size_t get_previous_size(block_header_t *ptr);
  123. /**
  124. * Get the size and the availability of the previous block (in the memory
  125. * space)
  126. *
  127. * \param ptr The pointer to the data part of the previous memory block.
  128. */
  129. size_t get_previous_size_availability(block_header_t *ptr);
  130. /**
  131. * Get the previous memory block on data layout level
  132. *
  133. * \param ptr The pointer to the data part of the current memory block.
  134. *
  135. * \return The pointer to the data part of the previous memory block on
  136. * data layout level.
  137. */
  138. block_header_t * get_dlprevious(block_header_t *ptr);
  139. /**
  140. * Get the next memory block on data layout level if there is one
  141. *
  142. * \param raw_block The pointer to the raw block which includes the block.
  143. * \param ptr The pointer to the data part of the current memory block.
  144. *
  145. * \return The pointer to the data part of the next block.
  146. * \retval NULL There is no next block.
  147. */
  148. block_header_t * get_dlnext(freelist_rb_t *raw_block, block_header_t *ptr);
  149. #endif /* BLOCK_HEADER_FUNCS_H */