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.

100 lines
2.8 KiB

  1. // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
  2. //
  3. // Copyright (c) 1985-2000 Microsoft Corporation
  4. //
  5. // This file is part of the Microsoft Research IPv6 Network Protocol Stack.
  6. // You should have received a copy of the Microsoft End-User License Agreement
  7. // for this software along with this release; see the file "license.txt".
  8. // If not, please see http://www.research.microsoft.com/msripv6/license.htm,
  9. // or write to Microsoft Research, One Microsoft Way, Redmond, WA 98052-6399.
  10. //
  11. // Abstract:
  12. //
  13. // TCP/UDP queuing definitions.
  14. //
  15. //
  16. // Definition of a queue linkage field.
  17. //
  18. typedef struct Queue {
  19. struct Queue *q_next;
  20. struct Queue *q_prev;
  21. } Queue;
  22. //
  23. // Initialize queue macro.
  24. //
  25. #define INITQ(q) { (q)->q_next = (q);\
  26. (q)->q_prev = (q); }
  27. //
  28. // Macro to check for queue empty.
  29. //
  30. #define EMPTYQ(q) ((q)->q_next == (q))
  31. //
  32. // Place an element onto the end of the queue.
  33. //
  34. #define ENQUEUE(q, e) { (q)->q_prev->q_next = (e);\
  35. (e)->q_prev = (q)->q_prev;\
  36. (q)->q_prev = (e);\
  37. (e)->q_next = (q); }
  38. //
  39. // Remove an element from the head of the queue. This macro assumes the queue
  40. // is not empty. The element is returned as type t, queued through linkage l.
  41. //
  42. #define DEQUEUE(q, ptr, t, l) {\
  43. Queue *__tmp__;\
  44. \
  45. __tmp__ = (q)->q_next;\
  46. (q)->q_next = __tmp__->q_next;\
  47. __tmp__->q_next->q_prev = (q);\
  48. (ptr) = CONTAINING_RECORD(__tmp__, t, l);\
  49. }
  50. //
  51. // Peek at an element at the head of the queue. Return a pointer to it
  52. // without removing anything.
  53. //
  54. #define PEEKQ(q, ptr, t, l) {\
  55. Queue *__tmp__;\
  56. \
  57. __tmp__ = (q)->q_next;\
  58. (ptr) = CONTAINING_RECORD(__tmp__, t, l);\
  59. }
  60. //
  61. // Macro to push an element onto the head of a queue.
  62. //
  63. #define PUSHQ(q, e) { (e)->q_next = (q)->q_next;\
  64. (q)->q_next->q_prev = (e);\
  65. (e)->q_prev = (q);\
  66. (q)->q_next = e; }
  67. //
  68. // Macro to remove an element from the middle of a queue.
  69. //
  70. #define REMOVEQ(q) { (q)->q_next->q_prev = (q)->q_prev;\
  71. (q)->q_prev->q_next = (q)->q_next; }
  72. //
  73. // The following macros define methods for working with queue without
  74. // dequeueing, mostly dealing with Queue structures directly.
  75. //
  76. // Macro to define the end of a Q, used in walking a queue sequentially.
  77. #define QEND(q) (q)
  78. // Macro to get the first on a queue.
  79. #define QHEAD(q) (q)->q_next
  80. // Macro to get a structure, given a queue.
  81. #define QSTRUCT(t, q, l) CONTAINING_RECORD((q), t, l)
  82. // Macro to get the next thing on q queue.
  83. #define QNEXT(q) (q)->q_next