home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / iodmutex.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  4KB  |  162 lines

  1. /* @(#)Z 1.4 os2/src/storage/iodmutex.cpp, oddataxfer, od96os2, odos29712d 97/03/21 17:38:59 (96/08/23 01:44:06) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: oddataxfer
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29.  
  30. #ifdef _PLATFORM_OS2_
  31. #include <odpagtun.h>
  32. #endif
  33.  
  34. #ifdef _PLATFORM_OS2_
  35. #ifndef SOM_Module_iodmutex_Source
  36. #define SOM_Module_iodmutex_Source
  37. #endif
  38. #define IODMutex_Class_Source
  39. #define VARIABLE_MACROS
  40. #define METHOD_MACROS
  41.  
  42. #define INCL_DOSSEMAPHORES
  43. #define INCL_DOSERRORS
  44. #include <itrace.hpp>
  45. #include <os2.h>
  46. #include <itext.h>
  47.  
  48. #ifndef _ODTYPESM_
  49. #include <ODTypesM.xh>
  50. #endif
  51.  
  52. #ifndef _EXCEPT_
  53.   #include <Except.h>
  54. #endif
  55.  
  56. #ifndef SOM_Module_IODDefs_IOpenDoc_Defs_defined
  57.   #include <IODDefs.xh>
  58. #endif
  59.  
  60. #include "IODMutex.xih"
  61.  
  62. SOM_Scope void
  63. SOMLINK Acquire(IODMutex *somSelf,
  64.                 Environment *ev)
  65. {
  66.     IODMutexData *somThis = IODMutexGetData(somSelf);
  67.     IODMutexMethodDebug("IODMutex","acquire");
  68.  
  69.     if (ev->_major) ODSetSOMException(ev, kODNoError);    
  70.     APIRET rc = NO_ERROR;
  71.     if (_fMutex != kODNULL)
  72.     {
  73.         rc = DosRequestMutexSem(_fMutex, _fTimeOut);
  74.     }
  75.     else {
  76.       ODSetSOMException(ev, kODErrRequestMutexInvalidHandle);
  77.       return;
  78.     };
  79.  
  80.     switch (rc)
  81.     {
  82.       case NO_ERROR:
  83.         return;
  84.  
  85.       case ERROR_TIMEOUT:
  86.         ODSetSOMException(ev, kODErrRequestMutexTimeOut);
  87.         return;
  88.  
  89.       case ERROR_INTERRUPT:
  90.         ODSetSOMException(ev, kODErrRequestMutexInterrupt);
  91.         return;
  92.  
  93.       case ERROR_INVALID_HANDLE:
  94.         ODSetSOMException(ev, kODErrRequestMutexInvalidHandle);
  95.         return;
  96.  
  97.       case ERROR_TOO_MANY_SEM_REQUESTS:
  98.         ODSetSOMException(ev, kODErrRequestMutexTooManyRequests);
  99.         return;
  100.  
  101.       case ERROR_SEM_OWNER_DIED:
  102.         ODSetSOMException(ev, kODErrRequestMutexOwnerDied);
  103.         return;
  104.     }
  105. }
  106.  
  107. SOM_Scope void
  108. SOMLINK Release(IODMutex *somSelf,
  109.                 Environment *ev)
  110. {
  111.     IODMutexData *somThis = IODMutexGetData(somSelf);
  112.     IODMutexMethodDebug("IODMutex","release");
  113.  
  114.     if (ev->_major) ODSetSOMException(ev, kODNoError);
  115.     APIRET rc = DosReleaseMutexSem(_fMutex);
  116.  
  117.     switch (rc)
  118.     {
  119.       case NO_ERROR:
  120.         return;
  121.  
  122.       case ERROR_INVALID_HANDLE:
  123.         ODSetSOMException(ev, kODErrReleaseMutexInvalidHandle);
  124.         return;
  125.  
  126.       case ERROR_NOT_OWNER:
  127.         ODSetSOMException(ev, kODErrReleaseMutexNotOwner);
  128.         return;
  129.     }
  130. }
  131.  
  132. SOM_Scope void
  133. SOMLINK somInit(IODMutex *somSelf)
  134. {
  135.     IODMutexData *somThis = IODMutexGetData(somSelf);
  136.     IODMutexMethodDebug("IODMutex","somInit");
  137.  
  138.     IODMutex_parent_SOMObject_somInit(somSelf);
  139.  
  140.     _fMutex = kODNULL;
  141.       APIRET rc = DosCreateMutexSem((PSZ)NULL, &_fMutex, (ULONG)0, FALSE);
  142.  
  143.     _fTimeOut = 60000;
  144. }
  145.  
  146. SOM_Scope void
  147. SOMLINK somUninit(IODMutex *somSelf)
  148. {
  149.     IODMutexData *somThis = IODMutexGetData(somSelf);
  150.     IODMutexMethodDebug("IODMutex","somUninit");
  151.  
  152.     IODMutex_parent_SOMObject_somUninit(somSelf);
  153.  
  154.     if (_fMutex != kODNULL)
  155.     {
  156.       APIRET rc = DosCloseMutexSem(_fMutex);
  157.       _fMutex = kODNULL;
  158.     }
  159. }
  160.  
  161. #endif
  162.