Changeset 3206 for trunk/src/kernel32/vmutex.cpp
- Timestamp:
- Mar 23, 2000, 8:23:48 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/vmutex.cpp
r2802 r3206 1 /* $Id: vmutex.cpp,v 1. 8 2000-02-16 14:22:47 sandervl Exp $ */1 /* $Id: vmutex.cpp,v 1.9 2000-03-23 19:23:47 sandervl Exp $ */ 2 2 3 3 /* 4 4 * Mutex class 5 5 * 6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)6 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl) 7 7 * 8 * 9 * NOTE: When creating a shared mutex object, you must call the ctor, enter & 10 * leave with a 2nd parameter (HMTX *). This mutex handle must be located 11 * in the local data segment of the dll. 12 * This enables other processes than the one that created the mutex object 13 * to access it 8 14 * 9 15 * Project Odin Software License can be found in LICENSE.TXT 10 16 * 11 17 */ 12 #define INCL_DOSSEMAPHORES 18 #define INCL_DOSSEMAPHORES 19 #define INCL_DOSERRORS 13 20 #include <os2wrap.h> //Odin32 OS/2 api wrappers 14 21 #include <vmutex.h> … … 21 28 /******************************************************************************/ 22 29 /******************************************************************************/ 23 VMutex::VMutex(int fShared ) : waiting(0)30 VMutex::VMutex(int fShared, HMTX *phMutex) : waiting(0) 24 31 { 25 32 APIRET rc; 26 33 34 this->fShared = fShared; 27 35 rc = DosCreateMutexSem(NULL, &sem_handle, (fShared == VMUTEX_SHARED) ? DC_SEM_SHARED : 0, FALSE); 28 36 if(rc != 0) { 29 37 dprintf(("Error creating mutex %X\n", rc)); 30 38 sem_handle = 0; 39 } 40 if(fShared) { 41 *phMutex = sem_handle; 31 42 } 32 43 } … … 38 49 39 50 if(sem_handle) { 40 for(i=0;i<waiting;i++) { 41 DosReleaseMutexSem(sem_handle); 42 } 43 DosCloseMutexSem(sem_handle); 51 if(fShared != VMUTEX_SHARED) { 52 for(i=0;i<waiting;i++) { 53 DosReleaseMutexSem(sem_handle); 54 } 55 } 56 DosCloseMutexSem(sem_handle); 44 57 } 45 58 } 46 59 /******************************************************************************/ 47 60 /******************************************************************************/ 48 void VMutex::enter(ULONG timeout )61 void VMutex::enter(ULONG timeout, HMTX *phMutex) 49 62 { 63 APIRET rc; 64 65 if(fShared == VMUTEX_SHARED && phMutex == NULL) { 66 DebugInt3(); 67 return; 68 } 50 69 if(sem_handle) { 51 waiting++; 52 DosRequestMutexSem(sem_handle, timeout); 53 waiting--; 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--; 54 81 } 55 82 } 56 83 /******************************************************************************/ 57 84 /******************************************************************************/ 58 void VMutex::leave( )85 void VMutex::leave(HMTX *phMutex) 59 86 { 60 DosReleaseMutexSem(sem_handle); 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); 61 94 } 62 95 /******************************************************************************/
Note:
See TracChangeset
for help on using the changeset viewer.