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/mmap.cpp

    r8121 r8203  
    1 /* $Id: mmap.cpp,v 1.54 2002-03-24 13:10:30 sandervl Exp $ */
     1/* $Id: mmap.cpp,v 1.55 2002-04-07 15:44:11 sandervl Exp $ */
    22
    33/*
     
    2929#include <string.h>
    3030#include <win\virtual.h>
    31 #include <vmutex.h>
     31#include <odincrt.h>
    3232#include <handlemanager.h>
    3333#include "mmap.h"
     
    3838#include "dbglocal.h"
    3939
    40 //NOTE: This must be in the local data segment -> if a shared semaphore was
    41 //      created by a different process, the handle returned by DosOpenMutexSem
    42 //      will be returned in hGlobalMapMutex
    43 HMTX             hGlobalMapMutex = 0;
    44 
    4540//Global DLL Data
    4641#pragma data_seg(_GLOBALDATA)
    47 Win32MemMap     *Win32MemMap::memmaps = NULL;
    48 VMutex           globalmapMutex(VMUTEX_SHARED, &hGlobalMapMutex);
     42Win32MemMap  *Win32MemMap::memmaps = NULL;
     43CRITICAL_SECTION_OS2       globalmapcritsect = {0};
    4944#pragma data_seg()
    50 VMutex           globalviewMutex;
    5145Win32MemMapView *Win32MemMapView::mapviews = NULL;
    5246
     47//******************************************************************************
     48//******************************************************************************
     49void InitializeMemMaps()
     50{
     51    if(globalmapcritsect.hmtxLock == 0) {
     52         dprintf(("InitializeMemMaps -> create shared critical section"));
     53         DosInitializeCriticalSection(&globalmapcritsect, MEMMAP_CRITSECTION_NAME);
     54    }
     55    else {
     56         dprintf(("InitializeMemMaps -> access shared critical section"));
     57         DosAccessCriticalSection(&globalmapcritsect, MEMMAP_CRITSECTION_NAME);
     58    }
     59}
    5360//******************************************************************************
    5461//TODO: sharing between processes
     
    5764               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0), image(0)
    5865{
    59     globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
     66    DosEnterCriticalSection(&globalmapcritsect);
    6067    next    = memmaps;
    6168    memmaps = this;
    62     globalmapMutex.leave(&hGlobalMapMutex);
     69    DosLeaveCriticalSection(&globalmapcritsect);
    6370
    6471    hMemFile   = hfile;
     
    8087               : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0), image(0)
    8188{
    82     globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
     89    DosEnterCriticalSection(&globalmapcritsect);
    8390    next    = memmaps;
    8491    memmaps = this;
    85     globalmapMutex.leave(&hGlobalMapMutex);
     92    DosLeaveCriticalSection(&globalmapcritsect);
    8693
    8794    hMemFile   = -1;
     
    169176    mapMutex.leave();
    170177
    171     globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
     178    DosEnterCriticalSection(&globalmapcritsect);
    172179    Win32MemMap *map = memmaps;
    173180
     
    186193        else dprintf(("Win32MemMap::~Win32MemMap: map not found!! (%x)", this));
    187194    }
    188     globalmapMutex.leave(&hGlobalMapMutex);
     195    DosLeaveCriticalSection(&globalmapcritsect);
    189196}
    190197//******************************************************************************
     
    511518    return NULL;
    512519
    513   globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
     520  DosEnterCriticalSection(&globalmapcritsect);
    514521  Win32MemMap *map = memmaps;
    515522
     
    521528    }
    522529  }
    523   globalmapMutex.leave(&hGlobalMapMutex);
     530  DosLeaveCriticalSection(&globalmapcritsect);
    524531  if(!map) dprintf(("Win32MemMap::findMap: couldn't find map %s", lpszName));
    525532  return map;
     
    529536Win32MemMap *Win32MemMap::findMap(ULONG address)
    530537{
    531   globalmapMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalMapMutex);
     538  DosEnterCriticalSection(&globalmapcritsect);
    532539  Win32MemMap *map = memmaps;
    533540
     
    542549    }
    543550  }
    544   globalmapMutex.leave(&hGlobalMapMutex);
     551  DosLeaveCriticalSection(&globalmapcritsect);
    545552  return map;
    546553}
     
    553560
    554561  //delete all maps created by this process
    555   globalviewMutex.enter();
     562  DosEnterCriticalSection(&globalmapcritsect);
    556563  while(map) {
    557564    nextmap = map->next;
     
    571578    map = nextmap;
    572579  }
    573   globalviewMutex.leave();
     580  DosLeaveCriticalSection(&globalmapcritsect);
    574581}
    575582//******************************************************************************
     
    630637    dprintf(("Win32MemMapView::Win32MemMapView: created %x (alias for %x), size %d", pMapView, viewaddr, size));
    631638
    632     globalviewMutex.enter();
     639    DosEnterCriticalSection(&globalmapcritsect);
    633640    if(tmpview == NULL || tmpview->getViewAddr() > pMapView) {
    634641        next     = mapviews;
     
    645652        tmpview->next = this;
    646653    }
    647     globalviewMutex.leave();
     654    DosLeaveCriticalSection(&globalmapcritsect);
    648655}
    649656//******************************************************************************
     
    667674    }
    668675
    669     globalviewMutex.enter();
     676    DosEnterCriticalSection(&globalmapcritsect);
    670677    Win32MemMapView *view = mapviews;
    671678
     
    684691        else    dprintf(("Win32MemMapView::~Win32MemMapView: map not found!! (%x)", this));
    685692    }
    686     globalviewMutex.leave();
     693    DosLeaveCriticalSection(&globalmapcritsect);
    687694}
    688695//******************************************************************************
     
    690697void Win32MemMapView::deleteViews(Win32MemMap *map)
    691698{
    692   globalviewMutex.enter();
     699  DosEnterCriticalSection(&globalmapcritsect);
    693700  Win32MemMapView *view = mapviews, *nextview;
    694701
     
    698705        if(view->getParentMap() == map)
    699706        {
    700             globalviewMutex.leave();
     707            DosLeaveCriticalSection(&globalmapcritsect);
    701708            delete view;
    702             globalviewMutex.enter();
     709            DosEnterCriticalSection(&globalmapcritsect);
    703710        }
    704711        view = nextview;
    705712    }
    706713  }
    707   globalviewMutex.leave();
     714  DosLeaveCriticalSection(&globalmapcritsect);
    708715}
    709716//******************************************************************************
     
    716723  if(mapviews == NULL) return NULL;
    717724
    718   globalviewMutex.enter();
     725  DosEnterCriticalSection(&globalmapcritsect);
    719726  Win32MemMapView *view = mapviews;
    720727  ULONG ulViewAddr;
     
    764771#endif
    765772
    766   globalviewMutex.leave();
     773  DosLeaveCriticalSection(&globalmapcritsect);
    767774
    768775  if(pView)
     
    777784  Win32MemMapView *view = mapviews;
    778785
    779   globalviewMutex.enter();
     786  DosEnterCriticalSection(&globalmapcritsect);
    780787  if(view != NULL) {
    781788    while(view) {
     
    787794    }
    788795  }
    789   globalviewMutex.leave();
     796  DosLeaveCriticalSection(&globalmapcritsect);
    790797  return view;
    791798}
Note: See TracChangeset for help on using the changeset viewer.