linked_lists.h 3.0 KB

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