Source code of Windows XP (NT5)
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.

66 lines
1.1 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. FLEXQ.H
  5. Abstract:
  6. This file defines CFlexQueue.
  7. History:
  8. --*/
  9. #ifndef __WBEM_FLEXQ__H_
  10. #define __WBEM_FLEXQ__H_
  11. class POLARITY CFlexQueue
  12. {
  13. protected:
  14. void** m_ppData;
  15. int m_nSize;
  16. int m_nHeadIndex;
  17. int m_nTailIndex;
  18. public:
  19. inline int GetQueueSize() const
  20. {
  21. if(m_nHeadIndex <= m_nTailIndex)
  22. return m_nTailIndex - m_nHeadIndex;
  23. else
  24. return m_nTailIndex - m_nHeadIndex + m_nSize;
  25. }
  26. protected:
  27. inline void IncrementIndex(int& nIndex)
  28. {
  29. if(++nIndex == m_nSize)
  30. nIndex = 0;
  31. }
  32. inline void DecrementIndex(int& nIndex)
  33. {
  34. if(nIndex-- == 0)
  35. nIndex = m_nSize - 1;
  36. }
  37. bool Grow();
  38. public:
  39. CFlexQueue(int nInitialSize = 1);
  40. ~CFlexQueue();
  41. bool Enqueue(void* pNew);
  42. void* Dequeue();
  43. bool Requeue(void* pNew);
  44. inline void* Unqueue()
  45. {
  46. if(GetQueueSize() == 0)
  47. return NULL;
  48. DecrementIndex(m_nTailIndex);
  49. return m_ppData[m_nTailIndex];
  50. }
  51. void* Peek();
  52. };
  53. #endif