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.

159 lines
3.1 KiB

  1. // $Header: G:/SwDev/WDM/Video/bt848/rcs/Queue.h 1.5 1998/05/08 18:18:52 tomz Exp $
  2. #ifndef __QUEUE_H
  3. #define __QUEUE_h
  4. const QueSize = 200;
  5. /* Class: VidBufQueue
  6. * Purpose: Queue of buffers to be sent to BtPisces
  7. */
  8. template <class T> class Queue
  9. {
  10. private:
  11. T Data [QueSize];
  12. T Dummy;
  13. unsigned items;
  14. unsigned left;
  15. unsigned right;
  16. unsigned size;
  17. public:
  18. bool IsFull();
  19. bool IsEmpty();
  20. unsigned Prev( unsigned index ) const;
  21. unsigned Next( unsigned index ) const;
  22. T Get();
  23. T GetRight();
  24. void Put( const T& t );
  25. T PeekLeft();
  26. T PeekRight();
  27. void Flush();
  28. int GetNumOfItems();
  29. Queue();
  30. ~Queue();
  31. };
  32. template <class T> bool Queue<T>::IsFull()
  33. {
  34. return right == Prev( left );
  35. }
  36. template <class T> bool Queue<T>::IsEmpty()
  37. {
  38. return !items;
  39. }
  40. template <class T> int Queue<T>::GetNumOfItems()
  41. {
  42. return items;
  43. }
  44. template <class T> unsigned Queue<T>::Prev( unsigned index ) const
  45. {
  46. if ( index == 0 )
  47. index = size;
  48. return --index;
  49. }
  50. template <class T> unsigned Queue<T>::Next( unsigned index ) const
  51. {
  52. index++;
  53. if ( index == size )
  54. index = 0;
  55. return index;
  56. }
  57. template <class T> T Queue<T>::Get()
  58. {
  59. if(!items){
  60. DebugOut((0, "Queue::Get called on empty queue!!!\n"));
  61. // DEBUG_BREAKPOINT();
  62. return Dummy;
  63. }
  64. T t = Data [left];
  65. Data [left] = T();
  66. left = Next( left );
  67. items--;
  68. return t;
  69. }
  70. /* Method: Queue::GetRight
  71. * Purpose: Gets the next element
  72. * Note: Extreme caution must be used when calling this function. The caller must
  73. * make sure the queue is not empty before calling it. Otherwise bogus data
  74. * will be returned
  75. */
  76. template <class T> T Queue<T>::GetRight()
  77. {
  78. if(!items){
  79. DebugOut((0, "Queue::GetRight called on empty queue!!!\n"));
  80. // DEBUG_BREAKPOINT();
  81. return Dummy;
  82. }
  83. right = Prev( right );
  84. T t = Data [right];
  85. Data[right] = T();
  86. items--;
  87. return t;
  88. }
  89. template <class T> void Queue<T>::Flush()
  90. {
  91. if(items){
  92. DebugOut((0, "Queue::Flush called on non-empty queue, %d items lost!!!\n", items));
  93. // DEBUG_BREAKPOINT();
  94. }
  95. items = left = right = 0;
  96. }
  97. template <class T> void Queue<T>::Put( const T& t )
  98. {
  99. if ( items >= size ){
  100. DebugOut((0, "Queue::Put called on Full queue!!!\n"));
  101. // DEBUG_BREAKPOINT();
  102. return;
  103. }
  104. Data [right] = t;
  105. right = Next( right );
  106. items++;
  107. }
  108. template <class T> Queue<T>::Queue()
  109. : Data(), Dummy(), items( 0 ), left( 0 ), right( 0 ), size( QueSize )
  110. {
  111. }
  112. template <class T> T Queue<T>::PeekLeft()
  113. {
  114. if(!items){
  115. DebugOut((0, "Queue::PeekLeft called on empty queue!!!\n"));
  116. // DEBUG_BREAKPOINT();
  117. return Dummy;
  118. }
  119. return Data [left];
  120. }
  121. template <class T> T Queue<T>::PeekRight()
  122. {
  123. if(!items){
  124. DebugOut((0, "Queue::PeekRight called on empty queue!!!\n"));
  125. // DEBUG_BREAKPOINT();
  126. return Dummy;
  127. }
  128. return Data [Prev( right )];
  129. }
  130. template <class T> Queue<T>::~Queue()
  131. {
  132. }
  133. typedef Queue<PHW_STREAM_REQUEST_BLOCK> SRBQueue;
  134. #endif