home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xmusem.cpp < prev    next >
C/C++ Source or Header  |  1998-01-20  |  3KB  |  103 lines

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