home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / os2thred.zip / MSGQ.H < prev    next >
C/C++ Source or Header  |  1994-06-05  |  2KB  |  60 lines

  1. // Listing 7 -- Msgq.h
  2.  
  3. #if !defined(MSGQUEUE_INC)
  4. #define MSGQUEUE_INC
  5.  
  6. //-------------------------- defines -------------------------------
  7.  
  8. const USHORT MQ_DEF_QSIZE   = 10;
  9.  
  10. //------------------------------ Class -----------------------------
  11.  
  12. class MsgQueue {
  13. public:
  14.     MsgQueue (USHORT usQSz=MQ_DEF_QSIZE);
  15.     ~MsgQueue ();
  16.     
  17.     //--------------------------------------------------------------
  18.     // This method blocks until it acquires the mutual exclusion 
  19.     // semaphore for the queue. It then calls the private 
  20.     // method QPut to add the message to the queue.
  21.     VOID PostMsg (ULONG hobj, ULONG msg, MPARAM mp1, MPARAM mp2);
  22.  
  23.     //--------------------------------------------------------------
  24.     // This method blocks until a message is available on the queue.
  25.     // It then obtains the necessary mutual exclusion semaphores
  26.     // before calling the private method QGet.
  27.     BOOL WaitMsg(QMSG & qmsg);
  28.  
  29. private:
  30.     BOOL    QEmpty();        // returns TRUE if queue is empty
  31.  
  32.     //--------------------------------------------------------------------
  33.     // This function puts a message in the queue.  This function is
  34.     // private because it assumes that the proper mutual exclusion 
  35.     // semaphores have already been acquired.
  36.     // If the queue is full it will automatically grow, so it 
  37.     // cannot overflow until memory is exhausted.
  38.     VOID    QPut(    ULONG hobj,  // hwnd or object handle
  39.                     ULONG msg,        // msg ID
  40.                     MPARAM mp1,        // parameter 1
  41.                     MPARAM mp2);    // parameter 2
  42.  
  43.     //--------------------------------------------------------------------
  44.     // This function extracts a waiting message from the queue and fills
  45.     // the QMSG structure.  This is a private function because it does 
  46.     // no mutual exclusion and assumes a msg is indeed waiting at the 
  47.     // Front of the queue (it returns whatever is there, valid or not).
  48.     // This function does not block.
  49.     VOID    QGet (QMSG & pqmsg);
  50.  
  51.     HEV        hevItmRdy;        // Even semaphore to indicate item ready
  52.     HMTX    hmtx;            // Mutual exclusion semaphore
  53.     USHORT    Front, Rear;    // Queue pointers
  54.     USHORT    usQSize;        // Maximum number of queue entries
  55.     QMSG    *msgs;            // Array of QMSG structures
  56. };
  57.  
  58. //-------------------------- End of Header -------------------------
  59. #endif
  60.