prclist.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef prclist_h___
  6. #define prclist_h___
  7. #include "prtypes.h"
  8. typedef struct PRCListStr PRCList;
  9. /*
  10. ** Circular linked list
  11. */
  12. struct PRCListStr {
  13. PRCList *next;
  14. PRCList *prev;
  15. };
  16. /*
  17. ** Insert element "_e" into the list, before "_l".
  18. */
  19. #define PR_INSERT_BEFORE(_e,_l) \
  20. PR_BEGIN_MACRO \
  21. (_e)->next = (_l); \
  22. (_e)->prev = (_l)->prev; \
  23. (_l)->prev->next = (_e); \
  24. (_l)->prev = (_e); \
  25. PR_END_MACRO
  26. /*
  27. ** Insert element "_e" into the list, after "_l".
  28. */
  29. #define PR_INSERT_AFTER(_e,_l) \
  30. PR_BEGIN_MACRO \
  31. (_e)->next = (_l)->next; \
  32. (_e)->prev = (_l); \
  33. (_l)->next->prev = (_e); \
  34. (_l)->next = (_e); \
  35. PR_END_MACRO
  36. /*
  37. ** Return the element following element "_e"
  38. */
  39. #define PR_NEXT_LINK(_e) \
  40. ((_e)->next)
  41. /*
  42. ** Return the element preceding element "_e"
  43. */
  44. #define PR_PREV_LINK(_e) \
  45. ((_e)->prev)
  46. /*
  47. ** Append an element "_e" to the end of the list "_l"
  48. */
  49. #define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l)
  50. /*
  51. ** Insert an element "_e" at the head of the list "_l"
  52. */
  53. #define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l)
  54. /* Return the head/tail of the list */
  55. #define PR_LIST_HEAD(_l) (_l)->next
  56. #define PR_LIST_TAIL(_l) (_l)->prev
  57. /*
  58. ** Remove the element "_e" from it's circular list.
  59. */
  60. #define PR_REMOVE_LINK(_e) \
  61. PR_BEGIN_MACRO \
  62. (_e)->prev->next = (_e)->next; \
  63. (_e)->next->prev = (_e)->prev; \
  64. PR_END_MACRO
  65. /*
  66. ** Remove the element "_e" from it's circular list. Also initializes the
  67. ** linkage.
  68. */
  69. #define PR_REMOVE_AND_INIT_LINK(_e) \
  70. PR_BEGIN_MACRO \
  71. (_e)->prev->next = (_e)->next; \
  72. (_e)->next->prev = (_e)->prev; \
  73. (_e)->next = (_e); \
  74. (_e)->prev = (_e); \
  75. PR_END_MACRO
  76. /*
  77. ** Return non-zero if the given circular list "_l" is empty, zero if the
  78. ** circular list is not empty
  79. */
  80. #define PR_CLIST_IS_EMPTY(_l) \
  81. ((_l)->next == (_l))
  82. /*
  83. ** Initialize a circular list
  84. */
  85. #define PR_INIT_CLIST(_l) \
  86. PR_BEGIN_MACRO \
  87. (_l)->next = (_l); \
  88. (_l)->prev = (_l); \
  89. PR_END_MACRO
  90. #define PR_INIT_STATIC_CLIST(_l) \
  91. {(_l), (_l)}
  92. #endif /* prclist_h___ */