home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / baclsema.zip / IPCMUTEX.C < prev    next >
C/C++ Source or Header  |  1994-06-23  |  2KB  |  86 lines

  1. // ****************************************************************************
  2. //
  3. // Module:  ipcmutex.C
  4. // Author:  Dick Lam
  5. //
  6. // Purpose: C++ class source file for ipcMutexSemaphore
  7. //
  8. // Notes:  This class is derived from ipcSemaphore.  It is an interface class
  9. //         for mutex semaphores that can be used to control access to a shared
  10. //         resource across processes or threads.
  11. //
  12. // ****************************************************************************
  13.  
  14. #include "ipcmutex.h"
  15. #include "ossem.h"
  16.  
  17. // ****************************************************************************
  18.  
  19. // ipcMutexSemaphore - constructor
  20.  
  21. ipcMutexSemaphore::ipcMutexSemaphore(const char *name, ipcSemaphoreOp operation)
  22.    : ipcSemaphore(name, mutex, operation)
  23.  
  24. {
  25.    // check the state of the object
  26.    if (myState != good)
  27.       return;
  28.  
  29.    // create or open the semaphore
  30.    if (operation == semcreate)
  31.       myImpl->CreateMutex();
  32.    else if (operation == semaccess)
  33.       myImpl->OpenMutex();
  34. }
  35.  
  36. // ----------------------------------------------------------------------------
  37.  
  38. // ~ipcMutexSemaphore - destructor
  39.  
  40. ipcMutexSemaphore::~ipcMutexSemaphore()
  41.  
  42. {
  43.    // close the semaphore
  44.    if (myState == good)
  45.       myImpl->CloseMutex();
  46. }
  47.  
  48. // ----------------------------------------------------------------------------
  49.  
  50. // Query - returns the number of requests made of the semaphore
  51.  
  52. unsigned long ipcMutexSemaphore::Query()
  53.  
  54. {
  55.    if (myState == good)
  56.       return myImpl->QueryMutex();
  57.  
  58.    return 0L;
  59. }
  60.  
  61. // ----------------------------------------------------------------------------
  62.  
  63. // Request - requests the semaphore
  64.  
  65. void ipcMutexSemaphore::Request()
  66.  
  67. {
  68.    if (myState == good)
  69.       myImpl->RequestMutex();
  70. }
  71.  
  72. // ----------------------------------------------------------------------------
  73.  
  74. // Release - releases the semaphore
  75.  
  76. void ipcMutexSemaphore::Release()
  77.  
  78. {
  79.    if (myState == good)
  80.       myImpl->ReleaseMutex();
  81. }
  82.  
  83. // ****************************************************************************
  84.  
  85. // end of ipcmutex.C
  86.