linked_lists.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 2011 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 linked_lists.h
  19. * \author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * \date September, 2011
  21. *
  22. * \brief Linked list node header structure and functions.
  23. */
  24. #ifndef LINKED_LISTS_H
  25. #define LINKED_LISTS_H
  26. #include "dmm_config.h"
  27. #ifndef LEON3
  28. #include <stdint.h>
  29. #else
  30. #include <sys/types.h>
  31. #endif /* LEON3 */
  32. #include <dmmlib/heap.h>
  33. /** The type of the pointer to a list node */
  34. #ifndef LEON3
  35. typedef uintptr_t list_node_ptr;
  36. #else
  37. typedef void* list_node_ptr;
  38. #endif /* LEON3 */
  39. /** The header structure of a linked list node */
  40. typedef struct list_node_header_s {
  41. list_node_ptr next; /**< The pointer to the next node in the list */
  42. #ifdef BLOCKS_IN_DLL
  43. list_node_ptr previous; /**< The pointer to the previous node in the list */
  44. #endif /* BLOCKS_IN_DLL */
  45. } list_node_header_t;
  46. /**
  47. * Set the next memory block of a block in a linked list.
  48. *
  49. * \param block The pointer to the data part of the current memory
  50. * block.
  51. * \param next_block The pointer to the data part of the next memory block.
  52. */
  53. void set_next(void *block, void *next_block);
  54. /**
  55. * Get the next memory block in a linked list.
  56. *
  57. * \param ptr The pointer to the data part of the current memory block.
  58. *
  59. * \return The pointer of the data part of the next (in list) memory block.
  60. * \retval NULL There is no next memory block in the list.
  61. */
  62. void * get_next(void *ptr);
  63. #ifdef BLOCKS_IN_DLL
  64. /**
  65. * Set the previous memory block of a block in a linked list.
  66. *
  67. * \param block The pointer to the data part of the current memory
  68. * block.
  69. * \param previous_block The pointer to the data part of the previous memory
  70. * block.
  71. */
  72. void set_previous(void *previous, void *previous_block);
  73. /**
  74. * Get the previous memory block in a linked list.
  75. *
  76. * \param ptr The pointer to the data part of the current memory block.
  77. *
  78. * \return The pointer of the data part of the previous (in list) memory block.
  79. * \retval NULL There is no previous memory block in the list.
  80. */
  81. void * get_previous(void *ptr);
  82. #endif /* BLOCKS_IN_DLL */
  83. /**
  84. * Push a memory block to the head of a linked list.
  85. *
  86. * \param **block A pointer to the block to be put.
  87. * \param **starting_node A pointer to the starting memory block of the list.
  88. */
  89. void push_block(void **block, void **starting_node);
  90. #ifdef COUNT_HOPS
  91. /**
  92. * Removes a memory block from a linked list of memory blocks.
  93. *
  94. * \param *heap A pointer to the heap structure which contains the block.
  95. * \param **block A pointer to the block to be removed.
  96. * \param **starting_node A pointer to the starting memory block of the list.
  97. */
  98. void remove_block(heap_t *heap, void **block, void **starting_node);
  99. #else
  100. /**
  101. * Removes a memory block from a linked list of memory blocks.
  102. *
  103. * \param **block A pointer to the block to be removed.
  104. * \param **starting_node A pointer to the starting memory block of the list.
  105. */
  106. void remove_block(void **block, void **starting_node);
  107. #endif /* COUNT_HOPS */
  108. /**
  109. * Removes a memory block from any of the linked lists of free memory blocks.
  110. *
  111. * \param **block A pointer to the block to be removed.
  112. * \param *heap A pointer to the heap which manages the block.
  113. */
  114. void remove_block_from_lists(void **block, heap_t *heap);
  115. #endif /* LINKED_LISTS_H */