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.

94 lines
3.1 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // INTEL Corporation Proprietary Information
  3. // This listing is supplied under the terms of a license agreement with Intel
  4. // Corporation and many not be copied nor disclosed except in accordance
  5. // with the terms of that agreement.
  6. // Copyright (c) 11/95 Intel Corporation.
  7. //
  8. //
  9. // Module Name: que.h
  10. // Abstract: header file. Generic queing structure.
  11. // Environment: MSVC 2.0, OLE 2
  12. /////////////////////////////////////////////////////////////////////////////////
  13. //NOTE: To use this que structure, you must include this file. You create a Que object.
  14. // Using the que object you can call deque and enque. You can enqueue any object of a
  15. // class derived from QueItem. In that derived class you add any fields you will need.
  16. // (eg. a buffer pointer field, and a length field). There is no limit on the size of
  17. // the que.
  18. /////////////////////////////////////////////////////////////////////////////////
  19. #ifndef QUE_H
  20. #define QUE_H
  21. //Don't really need winsock2.h but it has guards against including
  22. //Winsock.h and it includes windows.h which is what I want.
  23. //#include <windows.h>
  24. #include <winsock2.h>
  25. #include <wtypes.h>
  26. class QueueItem {
  27. friend class Queue;
  28. private:
  29. QueueItem* m_pNext;
  30. QueueItem* m_pPrev;
  31. public:
  32. QueueItem::QueueItem(){m_pNext = NULL; m_pPrev= NULL;}
  33. }; //end QueItem class
  34. ///////////////////////////////////////
  35. class Queue {
  36. private:
  37. QueueItem* m_pHead;
  38. QueueItem* m_pTail;
  39. int m_NumItems;
  40. CRITICAL_SECTION m_CritSect;
  41. public:
  42. // constructor
  43. Queue();
  44. //inline destructor
  45. ~Queue(){DeleteCriticalSection(&m_CritSect);}
  46. // NOTE:
  47. // Enqueue and Dequeue(void) are protected against simultaneous access by multiple threads.
  48. // Obviously, this protection does not extend to threads using GetHead, GetTail, GetPrev, GetNext,
  49. // and Dequeue(QueueItem *). Any threads using these functions and any other threads operating
  50. // on the same queue must use an additional critical section.
  51. //Add item to end of queue. Returns E_FAIL for a corrupt que or NOERROR for success
  52. HRESULT Enqueue(QueueItem* item);
  53. //Remove and return first item in queue. Returns NULL if queue is empty.
  54. QueueItem* Dequeue();
  55. //Remove a specific item from queue
  56. void Dequeue(QueueItem *);
  57. //Return first item in queue without removing it. Returns NULL if queue is empty.
  58. QueueItem *GetHead() { return m_pHead; };
  59. //Return last item in queue without removing it. Returns NULL if queue is empty.
  60. QueueItem *GetTail() { return m_pTail; };
  61. //Return the item following the item specified. Returns NULL if specified item is the last in the queue.
  62. QueueItem *GetNext(QueueItem *item) { return item->m_pNext; };
  63. //Return the item preceding the item specified. Returns NULL if specified item is the first in the queue.
  64. QueueItem *GetPrev(QueueItem *item) { return item->m_pPrev; };
  65. //inline. Checks to see if que is empty
  66. BOOL Is_Empty() {return (BOOL)(!(m_pHead) && !(m_pTail));};
  67. //inline returns number of items in list.
  68. int NumItems() {return m_NumItems;};
  69. }; //end Queue class
  70. #endif