Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.4 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. intrlk.h
  5. Abstract:
  6. This module contains platform independent interlocked functions.
  7. Author:
  8. David N. Cutler (davec) 15-Feb-2001
  9. Revision History:
  10. --*/
  11. #ifndef _INTRLK_
  12. #define _INTRLK_
  13. //
  14. // The following functions implement interlocked singly linked lists.
  15. //
  16. // WARNING: These lists can only be used when it is known that the ABA
  17. // removal problem cannot occur. If the ABA problem can occur,
  18. // then SLIST's should be used.
  19. //
  20. FORCEINLINE
  21. PSINGLE_LIST_ENTRY
  22. InterlockedPopEntrySingleList (
  23. IN PSINGLE_LIST_ENTRY ListHead
  24. )
  25. /*
  26. Routine Description:
  27. This function pops an entry from the front of a singly linked list.
  28. Arguments:
  29. ListHead - Supplies a pointer to the listhead of a singly linked list.
  30. Return Value:
  31. If the list is empty, then NULL is returned. Otherwise, the address of the
  32. first entry removed from the list is returned as the function
  33. value.
  34. */
  35. {
  36. PSINGLE_LIST_ENTRY FirstEntry;
  37. PSINGLE_LIST_ENTRY NextEntry;
  38. FirstEntry = ListHead->Next;
  39. do {
  40. if (FirstEntry == NULL) {
  41. return NULL;
  42. }
  43. NextEntry = FirstEntry;
  44. FirstEntry =
  45. (PSINGLE_LIST_ENTRY)InterlockedCompareExchangePointer((PVOID *)ListHead,
  46. FirstEntry->Next,
  47. FirstEntry);
  48. } while (FirstEntry != NextEntry);
  49. return FirstEntry;
  50. }
  51. FORCEINLINE
  52. PSINGLE_LIST_ENTRY
  53. InterlockedPushEntrySingleList (
  54. IN PSINGLE_LIST_ENTRY ListHead,
  55. IN PSINGLE_LIST_ENTRY Entry
  56. )
  57. /*
  58. Routine Description:
  59. This function pushes an entry onto the front of a singly linked list.
  60. Arguments:
  61. ListHead - Supplies a pointer to the listhead of a singly linked list.
  62. Entry - Supplies a pointer to a single list entry.
  63. Return Value:
  64. The previous contents of the listhead are returned as the function value.
  65. If NULL is returned, then the list transitioned for an empty to a non
  66. empty state.
  67. */
  68. {
  69. PSINGLE_LIST_ENTRY FirstEntry;
  70. PSINGLE_LIST_ENTRY NextEntry;
  71. FirstEntry = ListHead->Next;
  72. do {
  73. Entry->Next = FirstEntry;
  74. NextEntry = FirstEntry;
  75. FirstEntry =
  76. (PSINGLE_LIST_ENTRY)InterlockedCompareExchangePointer((PVOID *)ListHead,
  77. Entry,
  78. FirstEntry);
  79. } while (FirstEntry != NextEntry);
  80. return FirstEntry;
  81. }
  82. FORCEINLINE
  83. PSINGLE_LIST_ENTRY
  84. InterlockedFlushSingleList (
  85. IN PSINGLE_LIST_ENTRY ListHead
  86. )
  87. /*
  88. Routine Description:
  89. This function pops the entire list from the front of a singly linked list.
  90. Arguments:
  91. ListHead - Supplies a pointer to the listhead of a singly linked list.
  92. Return Value:
  93. If the list is empty, then NULL is returned. Otherwise, the address of the
  94. first entry removed from the list is returned as the function
  95. value.
  96. */
  97. {
  98. return (PSINGLE_LIST_ENTRY)InterlockedExchangePointer((PVOID *)ListHead,
  99. NULL);
  100. }
  101. #endif // _INTRLK_