VirtualBox

Changeset 19991 in vbox


Ignore:
Timestamp:
May 25, 2009 10:41:07 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
47697
Message:

pdmcritsect: work in progress.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PDMCritSect.cpp

    r19735 r19991  
    55
    66/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020 */
    2121
     22//#define PDM_WITH_R3R0_CRIT_SECT
    2223
    2324/*******************************************************************************
     
    2930#include <VBox/mm.h>
    3031#include <VBox/vm.h>
     32
    3133#include <VBox/err.h>
    32 
    3334#include <VBox/log.h>
     35#ifdef PDM_WITH_R3R0_CRIT_SECT
     36# include <VBox/sup.h>
     37#endif
    3438#include <iprt/asm.h>
    3539#include <iprt/assert.h>
     40#include <iprt/string.h>
    3641#include <iprt/thread.h>
    37 #include <iprt/string.h>
    3842
    3943
     
    112116{
    113117    VM_ASSERT_EMT(pVM);
     118
     119#ifdef PDM_WITH_R3R0_CRIT_SECT
     120    /*
     121     * Allocate the semaphore.
     122     */
     123    AssertCompile(sizeof(SUPSEMEVENT) == sizeof(pCritSect->Core.EventSem));
     124    int rc = SUPSemEventCreate(pVM->pSession, (PSUPSEMEVENT)&pCritSect->Core.EventSem);
     125#else
    114126    int rc = RTCritSectInit(&pCritSect->Core);
     127#endif
    115128    if (RT_SUCCESS(rc))
    116129    {
    117         pCritSect->pVMR3         = pVM;
    118         pCritSect->pVMR0         = pVM->pVMR0;
    119         pCritSect->pVMRC         = pVM->pVMRC;
    120         pCritSect->pvKey         = pvKey;
    121         pCritSect->EventToSignal = NIL_RTSEMEVENT;
    122         pCritSect->pNext         = pVM->pdm.s.pCritSects;
    123         pCritSect->pszName       = RTStrDup(pszName);
     130#ifdef PDM_WITH_R3R0_CRIT_SECT
     131        /*
     132         * Initialize the structure (first bit is c&p from RTCritSectInitEx).
     133         */
     134        pCritSect->Core.u32Magic             = RTCRITSECT_MAGIC;
     135        pCritSect->Core.fFlags               = 0;
     136        pCritSect->Core.cNestings            = 0;
     137        pCritSect->Core.cLockers             = -1;
     138        pCritSect->Core.NativeThreadOwner    = NIL_RTNATIVETHREAD;
     139        pCritSect->Core.Strict.ThreadOwner   = NIL_RTTHREAD;
     140        pCritSect->Core.Strict.pszEnterFile  = NULL;
     141        pCritSect->Core.Strict.u32EnterLine  = 0;
     142        pCritSect->Core.Strict.uEnterId      = 0;
     143#endif
     144        pCritSect->pVMR3                     = pVM;
     145        pCritSect->pVMR0                     = pVM->pVMR0;
     146        pCritSect->pVMRC                     = pVM->pVMRC;
     147        pCritSect->pvKey                     = pvKey;
     148        pCritSect->EventToSignal             = NIL_RTSEMEVENT;
     149        pCritSect->pNext                     = pVM->pdm.s.pCritSects;
     150        pCritSect->pszName                   = RTStrDup(pszName);
    124151        pVM->pdm.s.pCritSects = pCritSect;
    125152        STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLock,  STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionRZLock", pszName);
     
    185212static int pdmR3CritSectDeleteOne(PVM pVM, PPDMCRITSECTINT pCritSect, PPDMCRITSECTINT pPrev, bool fFinal)
    186213{
    187     /* ulink */
     214#ifdef PDM_WITH_R3R0_CRIT_SECT
     215    /*
     216     * Assert free waiters and so on (c&p from RTCritSectDelete).
     217     */
     218    Assert(pCritSect->Core.u32Magic == RTCRITSECT_MAGIC);
     219    Assert(pCritSect->Core.cNestings == 0);
     220    Assert(pCritSect->Core.cLockers == -1);
     221    Assert(pCritSect->Core.NativeThreadOwner == NIL_RTNATIVETHREAD);
     222#endif
     223
     224    /*
     225     * Unlink it.
     226     */
    188227    if (pPrev)
    189228        pPrev->pNext = pCritSect->pNext;
     
    191230        pVM->pdm.s.pCritSects = pCritSect->pNext;
    192231
    193     /* delete */
     232    /*
     233     * Delete it (parts taken from RTCritSectDelete).
     234     * In case someone is waiting we'll signal the semaphore cLockers + 1 times.
     235     */
     236#ifdef PDM_WITH_R3R0_CRIT_SECT
     237    ASMAtomicWriteU32(&pCritSect->Core.u32Magic, 0);
     238    SUPSEMEVENT hEvent = (SUPSEMEVENT)pCritSect->Core.EventSem;
     239    pCritSect->Core.EventSem = NIL_RTSEMEVENT;
     240    while (pCritSect->Core.cLockers-- >= 0)
     241        SUPSemEventSignal(pVM->pSession, hEvent);
     242    ASMAtomicWriteS32(&pCritSect->Core.cLockers, -1);
     243    int rc = SUPSemEventClose(pVM->pSession, hEvent);
     244    AssertRC(rc);
     245#endif
    194246    pCritSect->pNext   = NULL;
    195247    pCritSect->pvKey   = NULL;
     
    208260#endif
    209261    }
    210     return RTCritSectDelete(&pCritSect->Core);
     262#ifndef PDM_WITH_R3R0_CRIT_SECT
     263    int rc = RTCritSectDelete(&pCritSect->Core);
     264#endif
     265    return rc;
    211266}
    212267
     
    306361    {
    307362        PPDMCRITSECT pCritSect = pVCpu->pdm.s.apQueuedCritSectsLeaves[i];
     363#ifdef PDM_WITH_R3R0_CRIT_SECT
     364        int rc = pdmCritSectLeave(pCritSect);
     365#else
    308366        int rc = RTCritSectLeave(&pCritSect->s.Core);
     367#endif
    309368        LogFlow(("PDMR3CritSectFF: %p - %Rrc\n", pCritSect, rc));
    310369        AssertRC(rc);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette