VirtualBox

Ignore:
Timestamp:
Dec 14, 2009 4:31:40 PM (15 years ago)
Author:
vboxsync
Message:

RTCritSect,PDMCritSect,iprt/lockvalidator.h: Reworked the deadlocking detection for critical sections and preparing for lock order validation. This change generalizes the RTCRITSECT::Strict data and moves it out of the RTCRITSECT, leaving a pointer behind. This saves a bit of space in release builds.

File:
1 edited

Legend:

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

    r23350 r25368  
    126126    if (RT_SUCCESS(rc))
    127127    {
    128         /*
    129          * Initialize the structure (first bit is c&p from RTCritSectInitEx).
    130          */
    131         pCritSect->Core.u32Magic             = RTCRITSECT_MAGIC;
    132         pCritSect->Core.fFlags               = 0;
    133         pCritSect->Core.cNestings            = 0;
    134         pCritSect->Core.cLockers             = -1;
    135         pCritSect->Core.NativeThreadOwner    = NIL_RTNATIVETHREAD;
    136         pCritSect->Core.Strict.ThreadOwner   = NIL_RTTHREAD;
    137         pCritSect->Core.Strict.pszEnterFile  = NULL;
    138         pCritSect->Core.Strict.u32EnterLine  = 0;
    139         pCritSect->Core.Strict.uEnterId      = 0;
    140         pCritSect->pVMR3                     = pVM;
    141         pCritSect->pVMR0                     = pVM->pVMR0;
    142         pCritSect->pVMRC                     = pVM->pVMRC;
    143         pCritSect->pvKey                     = pvKey;
    144         pCritSect->EventToSignal             = NIL_RTSEMEVENT;
    145         pCritSect->pNext                     = pVM->pdm.s.pCritSects;
    146         pCritSect->pszName                   = RTStrDup(pszName);
    147         pVM->pdm.s.pCritSects = pCritSect;
    148         STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLock,  STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionRZLock", pszName);
    149         STAMR3RegisterF(pVM, &pCritSect->StatContentionRZUnlock,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionRZUnlock", pszName);
    150         STAMR3RegisterF(pVM, &pCritSect->StatContentionR3,      STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionR3", pszName);
     128        rc = RTLockValidatorCreate(&pCritSect->Core.pValidatorRec, NIL_RTLOCKVALIDATORCLASS, 0, pszName, pCritSect);
     129        if (RT_SUCCESS(rc))
     130        {
     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->pVMR3                     = pVM;
     140            pCritSect->pVMR0                     = pVM->pVMR0;
     141            pCritSect->pVMRC                     = pVM->pVMRC;
     142            pCritSect->pvKey                     = pvKey;
     143            pCritSect->EventToSignal             = NIL_RTSEMEVENT;
     144            pCritSect->pNext                     = pVM->pdm.s.pCritSects;
     145            pCritSect->pszName                   = RTStrDup(pszName);
     146            pVM->pdm.s.pCritSects = pCritSect;
     147            STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLock,  STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionRZLock", pszName);
     148            STAMR3RegisterF(pVM, &pCritSect->StatContentionRZUnlock,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionRZUnlock", pszName);
     149            STAMR3RegisterF(pVM, &pCritSect->StatContentionR3,      STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionR3", pszName);
    151150#ifdef VBOX_WITH_STATISTICS
    152         STAMR3RegisterF(pVM, &pCritSect->StatLocked,        STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, NULL, "/PDM/CritSects/%s/Locked", pszName);
     151            STAMR3RegisterF(pVM, &pCritSect->StatLocked,        STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, NULL, "/PDM/CritSects/%s/Locked", pszName);
    153152#endif
     153            return VINF_SUCCESS;
     154        }
     155
     156        SUPSemEventClose(pVM->pSession, (SUPSEMEVENT)pCritSect->Core.EventSem);
    154157    }
    155158    return rc;
     
    241244    int rc = SUPSemEventClose(pVM->pSession, hEvent);
    242245    AssertRC(rc);
     246    RTLockValidatorDestroy(&pCritSect->Core.pValidatorRec);
    243247    pCritSect->pNext   = NULL;
    244248    pCritSect->pvKey   = NULL;
     
    390394        return false;
    391395
     396#ifdef PDMCRITSECT_STRICT
     397    const char * const pszFile      = pCritSect->s.Core.pValidatorRec->pszFile;
     398    const char * const pszFunction  = pCritSect->s.Core.pValidatorRec->pszFunction;
     399    uint32_t     const iLine        = pCritSect->s.Core.pValidatorRec->uLine;
     400    RTHCUINTPTR  const uId          = pCritSect->s.Core.pValidatorRec->uId;
     401#endif
    392402    PDMCritSectLeave(pCritSect);
    393403
     
    411421    }
    412422
     423#ifdef PDMCRITSECT_STRICT
     424    int rc = PDMCritSectEnterDebug(pCritSect, VERR_INTERNAL_ERROR, uId, pszFile, iLine, pszFunction);
     425#else
    413426    int rc = PDMCritSectEnter(pCritSect, VERR_INTERNAL_ERROR);
     427#endif
    414428    AssertLogRelRC(rc);
    415429    return true;
Note: See TracChangeset for help on using the changeset viewer.

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