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.

116 lines
4.3 KiB

  1. //---- queue.h
  2. // Copyright 1996 Comtrol Corporation. All rights reserved.
  3. #ifndef BYTE
  4. #define BYTE UCHAR
  5. #endif
  6. //----- a queue data type
  7. typedef struct {
  8. unsigned char *QBase; // points to base of buffer
  9. int QSize; // total Q size
  10. int QGet; // get index
  11. int QPut; // put index
  12. } Queue;
  13. /*----------------------------------
  14. q_full - return true if queue is full.
  15. |----------------------------------*/
  16. #define q_full(q) ((((q)->QGet + 1) % (q)->QSize) == (q)->QPut)
  17. /*----------------------------------
  18. q_empty - return true if queue is empty.
  19. |----------------------------------*/
  20. #define q_empty(q) ((q)->QGet == (q)->QPut)
  21. /*----------------------------------
  22. q_put_flush - flush the queue, empty it out.
  23. |----------------------------------*/
  24. #define q_put_flush(q) (q)->QPut = (q)->QGet
  25. /*----------------------------------
  26. q_get_flush - flush the queue, empty it out.
  27. |----------------------------------*/
  28. #define q_get_flush(q) (q)->QGet = (q)->QPut
  29. #define q_flush q_get_flush
  30. /*----------------------------------
  31. q_room_put_till_wrap - return number of chars we can put in queue up to the
  32. wrap point(end of the queue). Assumes we already checked to see if
  33. the total number will fit in the queue using q_room().
  34. |----------------------------------*/
  35. #define q_room_put_till_wrap(q) \
  36. ( (q)->QSize - (q)->QPut)
  37. /*----------------------------------
  38. q_room_get_till_wrap - return number of chars we can get in queue up to the
  39. wrap point(end of the queue). Assumes we already checked to see if
  40. the total number is available from the the queue using q_count().
  41. |----------------------------------*/
  42. #define q_room_get_till_wrap(q) \
  43. ( (q)->QSize - (q)->QGet)
  44. /*----------------------------------
  45. q_room - return number of chars room in queue we can put.
  46. if (QRoom = (queue->QPut - queue->QGet -1) < 0)
  47. QRoom += queue->QSize;
  48. |----------------------------------*/
  49. int q_room(Queue *queue);
  50. /* #define q_room(q) \
  51. ( (((q)->QGet - (q)->QPut) <= 0) ? \
  52. ((q)->QGet - (q)->QPut - 1 + (q)->QSize) : \
  53. ((q)->QGet - (q)->QPut - 1) )
  54. to many references to QPut, contentious!
  55. */
  56. /*----------------------------------
  57. q_count - return number of chars in queue we can get.
  58. if (QCount = (queue->QPut - queue->QGet) < 0)
  59. QCount += queue->QSize;
  60. |----------------------------------*/
  61. int q_count(Queue *queue);
  62. /* #define q_count(q) \
  63. ( (((q)->QPut - (q)->QGet) < 0) ? \
  64. ((q)->QPut - (q)->QGet + (q)->QSize) : \
  65. ((q)->QPut - (q)->QGet) )
  66. to many references to QPut, contentious!
  67. */
  68. /*----------------------------------
  69. q_put_one - put a single character in the queue. No check for room
  70. done, so do a if (!q_full(q)) prior to calling
  71. |----------------------------------*/
  72. #define q_put_one(q, c) \
  73. (q)->QBase[(q)->QPut] = c; \
  74. (q)->QPut += 1; \
  75. (q)->QPut %= (q)->QSize;
  76. /*--------------------------------------------------------------------------
  77. | q_got - do the arithmetic to update the indexes if someone pulled Count
  78. many bytes from the queue.
  79. |--------------------------------------------------------------------------*/
  80. #define q_got(q, _cnt) \
  81. ( (q)->QGet = ((q)->QGet + _cnt) % (q)->QSize )
  82. /*--------------------------------------------------------------------------
  83. | q_putted - do the arithmetic to update the indexes if someone stuffed _cnt
  84. many bytes into the queue.
  85. |--------------------------------------------------------------------------*/
  86. #define q_putted(q, _cnt) \
  87. ( (q)->QPut = ((q)->QPut + _cnt) % (q)->QSize )
  88. /*--------------------------------------------------------------------------
  89. | q_flush_amount - flush an amount out of the queue on the get side.
  90. Used for debugger queue, where we want to dispose oldest so we
  91. always have room to put new.
  92. Assumed that called checks that there are enough bytes in the queue
  93. to clear prior to calling.
  94. |--------------------------------------------------------------------------*/
  95. #define q_flush_amount(q,bytes) \
  96. { q->QGet = (q->QGet + bytes) % q->QSize; }
  97. int q_flush_count_get(Queue *queue);
  98. int q_flush_count_put(Queue *queue);
  99. int q_get(Queue *queue, unsigned char *buf, int Count);
  100. int q_put(Queue *queue, unsigned char *buf, int Count);