home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xmusem.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  3KB  |  96 lines

  1. #include "xmusem.h"
  2. #include "xsemex.h"
  3.  
  4.  
  5. /*@ XMutexSemaphore :: XMutexSemaphore(char * name, BOOL shared, BOOL owned)
  6. @group constructors/destructors
  7. @remarks    Create a XMutexSemaphore
  8. @parameters 
  9. <t '°' c=2>
  10. °char * name            °name of the semaphore WITHOUT leading '\\SEM32' 
  11. °BOOL shared            °if shared or not
  12. °BOOL owned                °TRUE=initial state is owned<BR>FALSE=initial state is not owned
  13. </t>
  14. @exceptions    If the method fails an exception of the type XSemaphoreException is thrown
  15. */
  16. XMutexSemaphore :: XMutexSemaphore(char * name, BOOL shared, BOOL owned)
  17. {
  18.    XString n = "\\SEM32\\";
  19.     n += name;
  20.    hev = 0;
  21.     LONG attr = 0;
  22.     if(shared)
  23.         attr |= DC_SEM_SHARED;
  24.     ULONG rc = DosCreateMutexSem( (char*) n, &hev, attr, owned);
  25.     if( rc )
  26.         OOLSemThrow( "Cannot create XMutexSemaphore", rc);
  27. }
  28.  
  29.  
  30. XMutexSemaphore :: ~XMutexSemaphore()
  31. {
  32.     if(hev)
  33.         Close();
  34. }
  35.  
  36.  
  37. /*@ XMutexSemaphore :: Close()
  38. @group misc
  39. @remarks    Crlose a XMutexSemaphore
  40. @exceptions    If the method fails an exception of the type XSemaphoreException is thrown
  41. */
  42. void XMutexSemaphore :: Close()
  43. {
  44.     ULONG rc = DosCloseMutexSem( hev);
  45.     if( rc )
  46.         OOLSemThrow( "Cannot close XMutexSemaphore", rc);    
  47.     hev = 0;
  48. }
  49.  
  50.  
  51. /*@ XMutexSemaphore :: XMutexSemaphore(char * name)
  52. @group constructors/destructors
  53. @remarks    Open a XMutexSemaphore
  54. @parameters char * name        name of the semaphore WITHOUT leading '\\SEM32'
  55. @exceptions    If the method fails an exception of the type XSemaphoreException is thrown
  56. */
  57. XMutexSemaphore :: XMutexSemaphore(char * name)
  58. {
  59.    XString n = "\\SEM32\\";
  60.     n += name;
  61.    hev = 0;
  62.     ULONG rc = DosOpenMutexSem( (char*) n, &hev);
  63.     if( rc )
  64.         OOLSemThrow( "Cannot open XMutexSemaphore", rc);    
  65. }
  66.  
  67.  
  68. /*@ XMutexSemaphore :: Release()
  69. @group misc
  70. @remarks    Release a XMutexSemaphore, the next semaphore get access.
  71. @exceptions    If the method fails an exception of the type XSemaphoreException is thrown
  72. */
  73. void XMutexSemaphore :: Release()
  74. {
  75.     ULONG rc = DosReleaseMutexSem( hev);
  76.     if( rc )
  77.         OOLSemThrow( "XMutexSemaphore::Release failed", rc);    
  78. }
  79.  
  80.  
  81. /*@ XMutexSemaphore :: Request(LONG timeOut)
  82. @group misc
  83. @remarks    Request a semaphore.
  84. @parameters    <t '°' c=2>
  85.     °LONG timeout    °-1=wait endless<BR> 0 = return at once<BR> other=time to wait max. (in milliseconds)
  86.     </t>
  87. @exceptions    If the method fails an exception of the type XSemaphoreException is thrown
  88. */
  89. void XMutexSemaphore :: Request(LONG timeOut)
  90. {
  91.     ULONG rc = DosRequestMutexSem( hev, timeOut);
  92.     if( rc )
  93.         OOLSemThrow( "XMutexSemaphore::Request failed", rc);
  94. }
  95.  
  96.