linked_lists.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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
  32. /** The type of the pointer to a list node */
  33. #ifndef LEON3
  34. typedef uintptr_t list_node_ptr;
  35. #else
  36. typedef void* list_node_ptr;
  37. #endif /* LEON3 */
  38. /** The header structure of a linked list node */
  39. typedef struct list_node_header_s {
  40. list_node_ptr next; /**< The pointer to the next node in the list */
  41. #ifdef BLOCKS_IN_DLL
  42. list_node_ptr previous; /**< The pointer to the previous node in the list */
  43. #endif /* BLOCKS_IN_DLL */
  44. } list_node_header_t;
  45. /**
  46. * Set the next memory block of a block in a linked list.
  47. *
  48. * \param block The pointer to the data part of the current memory
  49. * block.
  50. * \param next_block The pointer to the data part of the next memory block.
  51. */
  52. void set_next(void *block, void *next_block);
  53. /**
  54. * Get the next memory block in a linked list.
  55. *
  56. * \param ptr The pointer to the data part of the current memory block.
  57. *
  58. * \return The pointer of the data part of the next (in list) memory block.
  59. * \retval NULL There is no next memory block in the list.
  60. */
  61. void * get_next(void *ptr);
  62. #ifdef BLOCKS_IN_DLL
  63. /**
  64. * Set the previous memory block of a block in a linked list.
  65. *
  66. * \param block The pointer to the data part of the current memory
  67. * block.
  68. * \param previous_block The pointer to the data part of the previous memory
  69. * block.
  70. */
  71. void set_previous(void *previous, void *previous_block);
  72. /**
  73. * Get the previous memory block in a linked list.
  74. *
  75. * \param ptr The pointer to the data part of the current memory block.
  76. *
  77. * \return The pointer of the data part of the previous (in list) memory block.
  78. * \retval NULL There is no previous memory block in the list.
  79. */
  80. void * get_previous(void *ptr);
  81. #endif /* BLOCKS_IN_DLL */
  82. /**
  83. * Push a memory block to the head of a linked list.
  84. *
  85. * \param *block The block to be put.
  86. * \param *starting_node The starting memory block of the list.
  87. */
  88. void push_block(void *block, void *starting_node);
  89. /**
  90. * Removes a memory block from a linked list of memory blocks.
  91. *
  92. * \param *block The block to be removed.
  93. * \param *starting_node The starting memory block of the list.
  94. */
  95. void remove_block(void *block, void *starting_node);
  96. #endif /* LINKED_LISTS_H */