Changeset 8203 for trunk/src/kernel32/vmutex.cpp
- Timestamp:
- Apr 7, 2002, 5:44:11 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/vmutex.cpp
r3206 r8203 1 /* $Id: vmutex.cpp,v 1. 9 2000-03-23 19:23:47sandervl Exp $ */1 /* $Id: vmutex.cpp,v 1.10 2002-04-07 15:44:11 sandervl Exp $ */ 2 2 3 3 /* … … 19 19 #define INCL_DOSERRORS 20 20 #include <os2wrap.h> //Odin32 OS/2 api wrappers 21 #include <win32type.h> 21 22 #include <vmutex.h> 22 #include < win32type.h>23 #include <odincrt.h> 23 24 #include <misc.h> 24 25 … … 28 29 /******************************************************************************/ 29 30 /******************************************************************************/ 30 VMutex::VMutex( int fShared, HMTX *phMutex) : waiting(0)31 VMutex::VMutex() 31 32 { 32 APIRET rc; 33 34 this->fShared = fShared; 35 rc = DosCreateMutexSem(NULL, &sem_handle, (fShared == VMUTEX_SHARED) ? DC_SEM_SHARED : 0, FALSE); 36 if(rc != 0) { 37 dprintf(("Error creating mutex %X\n", rc)); 38 sem_handle = 0; 39 } 40 if(fShared) { 41 *phMutex = sem_handle; 42 } 33 DosInitializeCriticalSection(&critsect, NULL); 43 34 } 44 35 /******************************************************************************/ … … 46 37 VMutex::~VMutex() 47 38 { 48 int i; 49 50 if(sem_handle) { 51 if(fShared != VMUTEX_SHARED) { 52 for(i=0;i<waiting;i++) { 53 DosReleaseMutexSem(sem_handle); 54 } 55 } 56 DosCloseMutexSem(sem_handle); 57 } 58 } 59 /******************************************************************************/ 60 /******************************************************************************/ 61 void VMutex::enter(ULONG timeout, HMTX *phMutex) 62 { 63 APIRET rc; 64 65 if(fShared == VMUTEX_SHARED && phMutex == NULL) { 66 DebugInt3(); 67 return; 68 } 69 if(sem_handle) { 70 if(fShared == VMUTEX_SHARED && *phMutex == 0) { 71 //must open the shared semaphore first (other process created it) 72 *phMutex = sem_handle; 73 rc = DosOpenMutexSem(NULL, phMutex); 74 if(rc) { 75 DebugInt3(); 76 } 77 } 78 waiting++; 79 rc = DosRequestMutexSem((fShared == VMUTEX_SHARED) ? *phMutex : sem_handle, timeout); 80 waiting--; 81 } 82 } 83 /******************************************************************************/ 84 /******************************************************************************/ 85 void VMutex::leave(HMTX *phMutex) 86 { 87 if((fShared == VMUTEX_SHARED && phMutex == NULL) || 88 (fShared == VMUTEX_SHARED && *phMutex == 0)) { 89 DebugInt3(); 90 //should always call enter first... 91 return; 92 } 93 DosReleaseMutexSem((fShared == VMUTEX_SHARED) ? *phMutex : sem_handle); 39 DosDeleteCriticalSection(&critsect); 94 40 } 95 41 /******************************************************************************/
Note:
See TracChangeset
for help on using the changeset viewer.