prclist.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef prclist_h___
  38. #define prclist_h___
  39. #include "prtypes.h"
  40. typedef struct PRCListStr PRCList;
  41. /*
  42. ** Circular linked list
  43. */
  44. struct PRCListStr {
  45. PRCList *next;
  46. PRCList *prev;
  47. };
  48. /*
  49. ** Insert element "_e" into the list, before "_l".
  50. */
  51. #define PR_INSERT_BEFORE(_e,_l) \
  52. PR_BEGIN_MACRO \
  53. (_e)->next = (_l); \
  54. (_e)->prev = (_l)->prev; \
  55. (_l)->prev->next = (_e); \
  56. (_l)->prev = (_e); \
  57. PR_END_MACRO
  58. /*
  59. ** Insert element "_e" into the list, after "_l".
  60. */
  61. #define PR_INSERT_AFTER(_e,_l) \
  62. PR_BEGIN_MACRO \
  63. (_e)->next = (_l)->next; \
  64. (_e)->prev = (_l); \
  65. (_l)->next->prev = (_e); \
  66. (_l)->next = (_e); \
  67. PR_END_MACRO
  68. /*
  69. ** Return the element following element "_e"
  70. */
  71. #define PR_NEXT_LINK(_e) \
  72. ((_e)->next)
  73. /*
  74. ** Return the element preceding element "_e"
  75. */
  76. #define PR_PREV_LINK(_e) \
  77. ((_e)->prev)
  78. /*
  79. ** Append an element "_e" to the end of the list "_l"
  80. */
  81. #define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l)
  82. /*
  83. ** Insert an element "_e" at the head of the list "_l"
  84. */
  85. #define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l)
  86. /* Return the head/tail of the list */
  87. #define PR_LIST_HEAD(_l) (_l)->next
  88. #define PR_LIST_TAIL(_l) (_l)->prev
  89. /*
  90. ** Remove the element "_e" from it's circular list.
  91. */
  92. #define PR_REMOVE_LINK(_e) \
  93. PR_BEGIN_MACRO \
  94. (_e)->prev->next = (_e)->next; \
  95. (_e)->next->prev = (_e)->prev; \
  96. PR_END_MACRO
  97. /*
  98. ** Remove the element "_e" from it's circular list. Also initializes the
  99. ** linkage.
  100. */
  101. #define PR_REMOVE_AND_INIT_LINK(_e) \
  102. PR_BEGIN_MACRO \
  103. (_e)->prev->next = (_e)->next; \
  104. (_e)->next->prev = (_e)->prev; \
  105. (_e)->next = (_e); \
  106. (_e)->prev = (_e); \
  107. PR_END_MACRO
  108. /*
  109. ** Return non-zero if the given circular list "_l" is empty, zero if the
  110. ** circular list is not empty
  111. */
  112. #define PR_CLIST_IS_EMPTY(_l) \
  113. ((_l)->next == (_l))
  114. /*
  115. ** Initialize a circular list
  116. */
  117. #define PR_INIT_CLIST(_l) \
  118. PR_BEGIN_MACRO \
  119. (_l)->next = (_l); \
  120. (_l)->prev = (_l); \
  121. PR_END_MACRO
  122. #define PR_INIT_STATIC_CLIST(_l) \
  123. {(_l), (_l)}
  124. #endif /* prclist_h___ */