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.

130 lines
5.0 KiB

  1. /*****************************************************************************
  2. ** **
  3. ** COPYRIGHT (C) 2000, 2001 MKNET CORPORATION **
  4. ** DEVELOPED FOR THE MK7100-BASED VFIR PCI CONTROLLER. **
  5. ** **
  6. *****************************************************************************/
  7. /**********************************************************************
  8. Module Name:
  9. QUEUE.H
  10. **********************************************************************/
  11. //-------------------------------------------------------------------------
  12. // QueueInitList -- Macro which will initialize a queue to NULL.
  13. //-------------------------------------------------------------------------
  14. #define QueueInitList(_L) (_L)->Link.Flink = (_L)->Link.Blink = (PLIST_ENTRY)0;
  15. //-------------------------------------------------------------------------
  16. // QueueEmpty -- Macro which checks to see if a queue is empty.
  17. //-------------------------------------------------------------------------
  18. #define QueueEmpty(_L) (QueueGetHead((_L)) == (PMK7_LIST_ENTRY)0)
  19. //-------------------------------------------------------------------------
  20. // QueueGetHead -- Macro which returns the head of the queue, but does not
  21. // remove the head from the queue.
  22. //-------------------------------------------------------------------------
  23. #define QueueGetHead(_L) ((PMK7_LIST_ENTRY)((_L)->Link.Flink))
  24. //-------------------------------------------------------------------------
  25. // QueuePushHead -- Macro which puts an element at the head of the queue.
  26. //-------------------------------------------------------------------------
  27. #define QueuePushHead(_L,_E) \
  28. ASSERT(_L); \
  29. ASSERT(_E); \
  30. if (!((_E)->Link.Flink = (_L)->Link.Flink)) \
  31. { \
  32. (_L)->Link.Blink = (PLIST_ENTRY)(_E); \
  33. } \
  34. (_L)->Link.Flink = (PLIST_ENTRY)(_E);
  35. //-------------------------------------------------------------------------
  36. // QueueRemoveHead -- Macro which removes the head of the head of queue.
  37. //-------------------------------------------------------------------------
  38. #define QueueRemoveHead(_L) \
  39. { \
  40. PMK7_LIST_ENTRY ListElem; \
  41. ASSERT((_L)); \
  42. if (ListElem = (PMK7_LIST_ENTRY)(_L)->Link.Flink) /* then fix up our our list to point to next elem */ \
  43. { \
  44. if(!((_L)->Link.Flink = ListElem->Link.Flink)) /* rechain list pointer to next link */ \
  45. /* if the list pointer is null, null out the reverse link */ \
  46. (_L)->Link.Blink = (PLIST_ENTRY) 0; \
  47. } }
  48. //-------------------------------------------------------------------------
  49. // QueuePutTail -- Macro which puts an element at the tail (end) of the queue.
  50. //-------------------------------------------------------------------------
  51. #define QueuePutTail(_L,_E) \
  52. ASSERT(_L); \
  53. ASSERT(_E); \
  54. if ((_L)->Link.Blink) \
  55. { \
  56. ((PMK7_LIST_ENTRY)(_L)->Link.Blink)->Link.Flink = (PLIST_ENTRY)(_E); \
  57. (_L)->Link.Blink = (PLIST_ENTRY)(_E); \
  58. } \
  59. else \
  60. { \
  61. (_L)->Link.Flink = \
  62. (_L)->Link.Blink = (PLIST_ENTRY)(_E); \
  63. } \
  64. (_E)->Link.Flink = (PLIST_ENTRY)0;
  65. //-------------------------------------------------------------------------
  66. // QueueGetTail -- Macro which returns the tail of the queue, but does not
  67. // remove the tail from the queue.
  68. //-------------------------------------------------------------------------
  69. #define QueueGetTail(_L) ((PMK7_LIST_ENTRY)((_L)->Link.Blink))
  70. //-------------------------------------------------------------------------
  71. // QueuePopHead -- Macro which will pop the head off of a queue (list), and
  72. // return it (this differs only from queueremovehead only in the 1st line)
  73. //-------------------------------------------------------------------------
  74. #define QueuePopHead(_L) \
  75. (PMK7_LIST_ENTRY) (_L)->Link.Flink; QueueRemoveHead(_L);
  76. typedef struct _MK7_RESERVED {
  77. // next packet in the chain of queued packets being allocated,
  78. // or waiting for the finish of transmission.
  79. //
  80. // We always keep the packet on a list so that in case the
  81. // the adapter is closing down or resetting, all the packets
  82. // can easily be located and "canceled".
  83. //
  84. PNDIS_PACKET Next;
  85. } MK7_RESERVED,*PMK7_RESERVED;
  86. #define PMK7_RESERVED_FROM_PACKET(_Packet) \
  87. ((PMK7_RESERVED)((_Packet)->MiniportReserved))
  88. #define EnqueuePacket(_Head, _Tail, _Packet) \
  89. { \
  90. if (!_Head) { \
  91. _Head = _Packet; \
  92. } else { \
  93. PMK7_RESERVED_FROM_PACKET(_Tail)->Next = _Packet; \
  94. } \
  95. PMK7_RESERVED_FROM_PACKET(_Packet)->Next = NULL; \
  96. _Tail = _Packet; \
  97. }
  98. #define DequeuePacket(Head, Tail) \
  99. { \
  100. PMK7_RESERVED Reserved = \
  101. PMK7_RESERVED_FROM_PACKET(Head); \
  102. if (!Reserved->Next) { \
  103. Tail = NULL; \
  104. } \
  105. Head = Reserved->Next; \
  106. }