Changeset 8203 for trunk/src


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

Location:
trunk/src/kernel32
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/KERNEL32.DEF

    r7886 r8203  
    1 ; $Id: KERNEL32.DEF,v 1.132 2002-02-12 12:00:41 sandervl Exp $
     1; $Id: KERNEL32.DEF,v 1.133 2002-04-07 15:44:10 sandervl Exp $
    22
    33;Basis is Windows95 KERNEL32
     
    10771077
    10781078;VMutex
    1079    enter__6VMutexFUlPUl                                           @1204 NONAME
    1080    leave__6VMutexFPUl                                             @1205 NONAME
    1081    __ct__6VMutexFiPUl                                             @1206 NONAME
     1079;;   enter__6VMutexFUlPUl                                           @1204 NONAME
     1080;;   leave__6VMutexFPUl                                             @1205 NONAME
     1081   __ct__6VMutexFv                                                @1206 NONAME
    10821082   __dt__6VMutexFv                                                @1207 NONAME
    10831083
  • trunk/src/kernel32/initkernel32.cpp

    r8010 r8203  
    1 /* $Id: initkernel32.cpp,v 1.13 2002-02-24 20:29:56 sandervl Exp $
     1/* $Id: initkernel32.cpp,v 1.14 2002-04-07 15:44:10 sandervl Exp $
    22 *
    33 * KERNEL32 DLL entry point
     
    136136                return 0UL;
    137137
     138            InitializeMemMaps();
     139
    138140            PROFILE_LoadOdinIni();
    139141            dllHandle = RegisterLxDll(hModule, 0, (PVOID)&kernel32_PEResTab);
  • trunk/src/kernel32/kernel32dbg.def

    r7886 r8203  
    1 ; $Id: kernel32dbg.def,v 1.8 2002-02-12 12:00:42 sandervl Exp $
     1; $Id: kernel32dbg.def,v 1.9 2002-04-07 15:44:10 sandervl Exp $
    22
    33;Basis is Windows95 KERNEL32
     
    10771077
    10781078;VMutex
    1079    enter__6VMutexFUlPUl                                           @1204 NONAME
    1080    leave__6VMutexFPUl                                             @1205 NONAME
    1081    __ct__6VMutexFiPUl                                             @1206 NONAME
     1079;;   enter__6VMutexFUlPUl                                           @1204 NONAME
     1080;;   leave__6VMutexFPUl                                             @1205 NONAME
     1081   __ct__6VMutexFv                                                @1206 NONAME
    10821082   __dt__6VMutexFv                                                @1207 NONAME
    10831083
  • 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}
  • trunk/src/kernel32/mmap.h

    r7550 r8203  
    1 /* $Id: mmap.h,v 1.20 2001-12-05 18:06:02 sandervl Exp $ */
     1/* $Id: mmap.h,v 1.21 2002-04-07 15:44:11 sandervl Exp $ */
    22
    33/*
     
    2222#define PAGE_SHIFT  12
    2323#endif
     24
     25#define MEMMAP_CRITSECTION_NAME "\\SEM32\\ODIN_MMAP.SEM"
    2426
    2527//commit 4 pages at once when the app accesses it
     
    169171//******************************************************************************
    170172
     173void InitializeMemMaps();
     174
    171175#endif //__MMAP_H__
  • 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.