Ignore:
Timestamp:
Apr 7, 2002, 5:44:11 PM (23 years ago)
Author:
sandervl
Message:

use critical sections in vmutex; change global vmutex in mmap to use a shared critical section

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:47 sandervl Exp $ */
     1/* $Id: vmutex.cpp,v 1.10 2002-04-07 15:44:11 sandervl Exp $ */
    22
    33/*
     
    1919#define INCL_DOSERRORS
    2020#include <os2wrap.h>    //Odin32 OS/2 api wrappers
     21#include <win32type.h>
    2122#include <vmutex.h>
    22 #include <win32type.h>
     23#include <odincrt.h>
    2324#include <misc.h>
    2425
     
    2829/******************************************************************************/
    2930/******************************************************************************/
    30 VMutex::VMutex(int fShared, HMTX *phMutex) : waiting(0)
     31VMutex::VMutex()
    3132{
    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);
    4334}
    4435/******************************************************************************/
     
    4637VMutex::~VMutex()
    4738{
    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);
    9440}
    9541/******************************************************************************/
Note: See TracChangeset for help on using the changeset viewer.