ordering_policy.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 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 freelist/ordering_policy.h
  19. * \author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * \date October 2012
  21. *
  22. * \brief Defines the default ordering policy in freelist-organized raw blocks.
  23. */
  24. #ifndef FL_ORDERING_POLICY_H
  25. #define FL_ORDERING_POLICY_H
  26. #include <dmmlib/config.h>
  27. #include "dmmlib/lists.h"
  28. /**
  29. * @def ADD_BLOCK
  30. * Adds a block to the list of free memory blocks by using the default ordering
  31. * policy.
  32. *
  33. * @param block The block to be added.
  34. */
  35. #if defined (ADDRESS_ORDERED)
  36. #include "freelist/ordering/address.h"
  37. #define ADD_BLOCK(block) add_to_address_ordered(&raw_block->fl_head, block)
  38. #elif defined (FIFO_ORDERED)
  39. #include "freelist/ordering/fifo.h"
  40. #define ADD_BLOCK(block) add_to_fifo_ordered(raw_block, block)
  41. #elif defined (LIFO_ORDERED)
  42. #include "freelist/ordering/lifo.h"
  43. #define ADD_BLOCK(block) add_to_lifo_ordered(raw_block, block)
  44. #elif defined (SIZE_ORDERED)
  45. #include "freelist/ordering/size.h"
  46. #define ADD_BLOCK(block) add_to_size_ordered(&raw_block->fl_head, block)
  47. #endif /* ADDRESS_ORDERED */
  48. /**
  49. * @def REMOVE_FSLLIST_HEAD
  50. * Removes the top block of the list of free memory blocks.
  51. *
  52. * @param raw_block The pointer to the freelist-organized raw block.
  53. */
  54. /**
  55. * @def REMOVE_FSLLIST
  56. * Removes a memory block from the list of free memory blocks.
  57. *
  58. * @param raw_block The pointer to the freelist-organized raw block.
  59. * @param memory_block The pointer to the memory block to be removed.
  60. */
  61. #ifndef FIFO_ORDERED
  62. #define REMOVE_FSLLIST_HEAD(raw_block) \
  63. SLIST_REMOVE_HEAD(&raw_block->fl_head, pointers);
  64. #define REMOVE_FSLLIST(raw_block, memory_block) \
  65. SLIST_REMOVE(&raw_block->fl_head, memory_block, block_header_s, pointers);
  66. #else /* FIFO_ORDERED */
  67. #define REMOVE_FSLLIST_HEAD(raw_block) \
  68. if(raw_block->fl_tail == raw_block->fl_head.slh_first) { \
  69. raw_block->fl_tail = NULL; \
  70. } \
  71. SLIST_REMOVE_HEAD(&raw_block->fl_head, pointers);
  72. #define REMOVE_FSLLIST(raw_block, memory_block) do { \
  73. if ((&raw_block->fl_head)->slh_first == memory_block) { \
  74. REMOVE_FSLLIST_HEAD(raw_block); \
  75. } else { \
  76. block_header_t *curelm = (&raw_block->fl_head)->slh_first; \
  77. while(curelm->pointers.sle_next != memory_block) \
  78. curelm = curelm->pointers.sle_next; \
  79. if(raw_block->fl_tail == curelm->pointers.sle_next) { \
  80. raw_block->fl_tail = curelm; \
  81. } \
  82. curelm->pointers.sle_next = \
  83. curelm->pointers.sle_next->pointers.sle_next; \
  84. } \
  85. } while (/*CONSTCOND*/0)
  86. #endif /* FIFO_ORDERED */
  87. #endif /* FL_ORDERING_POLICY_H */