Queue.h
上传用户:royluo
上传日期:2007-01-05
资源大小:1584k
文件大小:3k
源码类别:

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   Queue.h
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Implements the queue base class.
  11. *                       
  12. *                                                                             
  13. *   Authors: Eran Yariv - 28484475                                           
  14. *            Moshe Zur  - 24070856                                           
  15. *                                                                            
  16. *                                                                            
  17. *   Date: 23/09/98                                                           
  18. *                                                                            
  19. ******************************************************************************/
  20. #ifndef __CQUEUE_H__
  21. #define __CQUEUE_H__
  22. /*-------------------------- INCLUDE SECTION---------------------------------*/
  23. #include <afxmt.h>
  24. /*------------------------ EXCEPTION SECTION --------------------------------*/
  25. /*------------------------ DEFINITION SECTION -------------------------------*/
  26. class CQueue
  27. {
  28. public:
  29. #define KILL_Q_MSG      ((CObject*)NULL)    
  30.     CQueue (BOOL bBlocking) :
  31.         m_bBlocking(bBlocking),
  32.         m_bQueueIsDead (FALSE),
  33.         m_hEnqueueEvent (NULL),
  34.         m_DispatchSem (0 /* Initial counter */, LONG_MAX /* there are INFINITY counters */)
  35.     {}
  36.     
  37.     virtual ~CQueue()   
  38.     { 
  39.         CloseQueue();
  40.     }
  41.     BOOL Enqueue (CObject* pNewElement);    // Insert new object into the queue
  42.     BOOL Enqueue (CObject* pNewElement, DWORD dwKey); // Insert new object to sorted Q
  43.     BOOL Dequeue(CObject*&);                // Remove an object out of the queue
  44.     int GetQueueSize();
  45.     void SetNotificationEvent (HANDLE);
  46.     void Empty();
  47. private: 
  48.     void CloseQueue ();
  49.     CObList             m_Queue;            // The queue's list
  50.     CCriticalSection    m_QueueCS;          // use to synchronize between the queue's actions
  51.     CSemaphore          m_DispatchSem;      // use to synchronize between the queue's content and reader
  52.     
  53.     BOOL                m_bQueueIsDead,     // TRUE if KILL_Q_MSG was dequeued
  54.                         m_bBlocking;        // TRUE if enqueue operation should wait until 
  55.                                             // there are items in the queue
  56.     HANDLE              m_hEnqueueEvent;    // Signalled when enqueue if performed.
  57. };                 
  58. #endif