VirtualBox

Changeset 25478 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Dec 18, 2009 12:58:10 PM (15 years ago)
Author:
vboxsync
Message:

IPRT,PDMCritSect: More lock validator refactoring.

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

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

    r25406 r25478  
    396396
    397397#ifdef PDMCRITSECT_STRICT
    398     const char * const pszFile      = pCritSect->s.Core.pValidatorRec->pszFile;
    399     const char * const pszFunction  = pCritSect->s.Core.pValidatorRec->pszFunction;
    400     uint32_t     const iLine        = pCritSect->s.Core.pValidatorRec->uLine;
    401     RTHCUINTPTR  const uId          = pCritSect->s.Core.pValidatorRec->uId;
     398    RTLOCKVALIDATORSRCPOS const SrcPos = pCritSect->s.Core.pValidatorRec->SrcPos;
    402399#endif
    403400    PDMCritSectLeave(pCritSect);
     
    423420
    424421#ifdef PDMCRITSECT_STRICT
    425     int rc = PDMCritSectEnterDebug(pCritSect, VERR_INTERNAL_ERROR, uId, pszFile, iLine, pszFunction);
     422    int rc = PDMCritSectEnterDebug(pCritSect, VERR_INTERNAL_ERROR,
     423                                   SrcPos.uId, SrcPos.pszFile, SrcPos.uLine, SrcPos.pszFunction);
    426424#else
    427425    int rc = PDMCritSectEnter(pCritSect, VERR_INTERNAL_ERROR);
  • trunk/src/VBox/VMM/VMMAll/PDMAllCritSect.cpp

    r25467 r25478  
    5252#define PDMCRITSECT_SPIN_COUNT_RC       256
    5353
    54 #ifdef PDMCRITSECT_STRICT
    55 # define PDMCRITSECT_STRICT_POS_DECL            RTHCUINTPTR uId, RT_SRC_POS_DECL
    56 # define PDMCRITSECT_STRICT_POS_ARGS            uId, RT_SRC_POS_ARGS
    57 # define PDMCRITSECT_STRICT_BLOCK_RET(hThread, pRec, fRecursive) \
    58     do { \
    59         int rc9 = RTLockValidatorCheckBlocking(pRec, (hThread), RTTHREADSTATE_CRITSECT, fRecursive, uId, RT_SRC_POS_ARGS); \
    60         if (RT_FAILURE(rc9)) \
    61             return rc9; \
    62     } while (0)
    63 #else
    64 # define PDMCRITSECT_STRICT_POS_DECL            int iDummy
    65 # define PDMCRITSECT_STRICT_POS_ARGS            0
    66 # define PDMCRITSECT_STRICT_BLOCK_RET(hThread, pRec, fRecursive) \
    67                                                 RTThreadBlocking((hThread), RTTHREADSTATE_CRITSECT)
    68 #endif
    69 #define  PDMCRITSECT_STRICT_UNBLOCK(hThread)    RTThreadUnblocked((hThread), RTTHREADSTATE_CRITSECT)
    7054
    7155/* Undefine the automatic VBOX_STRICT API mappings. */
     
    10488 * @param   hNativeSelf     The native handle of this thread.
    10589 */
    106 DECL_FORCE_INLINE(int) pdmCritSectEnterFirst(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PDMCRITSECT_STRICT_POS_DECL)
     90DECL_FORCE_INLINE(int) pdmCritSectEnterFirst(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    10791{
    10892    AssertMsg(pCritSect->s.Core.NativeThreadOwner == NIL_RTNATIVETHREAD, ("NativeThreadOwner=%p\n", pCritSect->s.Core.NativeThreadOwner));
     
    11397
    11498# ifdef PDMCRITSECT_STRICT
    115     RTLockValidatorSetOwner(pCritSect->s.Core.pValidatorRec, NIL_RTTHREAD, PDMCRITSECT_STRICT_POS_ARGS);
     99    RTLockValidatorSetOwner(pCritSect->s.Core.pValidatorRec, NIL_RTTHREAD, pSrcPos);
    116100# endif
    117101
     
    129113 * @param   hNativeSelf         The native thread handle.
    130114 */
    131 static int pdmR3CritSectEnterContended(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PDMCRITSECT_STRICT_POS_DECL)
     115static int pdmR3CritSectEnterContended(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    132116{
    133117    /*
     
    135119     */
    136120    if (ASMAtomicIncS32(&pCritSect->s.Core.cLockers) == 0)
    137         return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     121        return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    138122    STAM_COUNTER_INC(&pCritSect->s.StatContentionR3);
    139123
     
    141125     * The wait loop.
    142126     */
    143     PSUPDRVSESSION  pSession = pCritSect->s.CTX_SUFF(pVM)->pSession;
    144     SUPSEMEVENT     hEvent   = (SUPSEMEVENT)pCritSect->s.Core.EventSem;
     127    PSUPDRVSESSION  pSession    = pCritSect->s.CTX_SUFF(pVM)->pSession;
     128    SUPSEMEVENT     hEvent      = (SUPSEMEVENT)pCritSect->s.Core.EventSem;
    145129# ifdef PDMCRITSECT_STRICT
    146     RTTHREAD        hSelf    = RTThreadSelfAutoAdopt();
    147     int rc2 = RTLockValidatorCheckOrder(pCritSect->s.Core.pValidatorRec, hSelf, 0, NULL, 0, NULL);
     130    RTTHREAD        hThreadSelf = RTThreadSelfAutoAdopt();
     131    int rc2 = RTLockValidatorCheckOrder(pCritSect->s.Core.pValidatorRec, hThreadSelf, pSrcPos);
    148132    if (RT_FAILURE(rc2))
    149133        return rc2;
    150134# else
    151     RTTHREAD        hSelf    = RTThreadSelf();
     135    RTTHREAD        hThreadSelf = RTThreadSelf();
    152136# endif
    153137    for (;;)
    154138    {
    155         PDMCRITSECT_STRICT_BLOCK_RET(hSelf, pCritSect->s.Core.pValidatorRec, !(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING));
     139# ifdef PDMCRITSECT_STRICT
     140        int rc9 = RTLockValidatorCheckBlocking(pCritSect->s.Core.pValidatorRec, hThreadSelf, RTTHREADSTATE_CRITSECT,
     141                                               !(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING), pSrcPos);
     142        if (RT_FAILURE(rc9))
     143            return rc9;
     144# endif
     145
     146        RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT);
    156147        int rc = SUPSemEventWaitNoResume(pSession, hEvent, RT_INDEFINITE_WAIT);
    157         PDMCRITSECT_STRICT_UNBLOCK(hSelf);
     148        RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_CRITSECT);
     149
    158150        if (RT_UNLIKELY(pCritSect->s.Core.u32Magic != RTCRITSECT_MAGIC))
    159151            return VERR_SEM_DESTROYED;
    160152        if (rc == VINF_SUCCESS)
    161             return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     153            return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    162154        AssertMsg(rc == VERR_INTERRUPTED, ("rc=%Rrc\n", rc));
    163155    }
     
    178170 *                              and the section is busy.
    179171 */
    180 DECL_FORCE_INLINE(int) pdmCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy, PDMCRITSECT_STRICT_POS_DECL)
     172DECL_FORCE_INLINE(int) pdmCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    181173{
    182174    Assert(pCritSect->s.Core.cNestings < 8);  /* useful to catch incorrect locking */
     
    195187    /* Not owned ... */
    196188    if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1))
    197         return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     189        return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    198190
    199191    /* ... or nested. */
     
    215207    {
    216208        if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1))
    217             return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     209            return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    218210        ASMNopPause();
    219211        /** @todo Should use monitor/mwait on e.g. &cLockers here, possibly with a
     
    228220     * Take the slow path.
    229221     */
    230     return pdmR3CritSectEnterContended(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     222    return pdmR3CritSectEnterContended(pCritSect, hNativeSelf, pSrcPos);
    231223#else
    232224    /*
     
    254246{
    255247#ifndef PDMCRITSECT_STRICT
    256     return pdmCritSectEnter(pCritSect, rcBusy, PDMCRITSECT_STRICT_POS_ARGS);
    257 #else
    258     /* No need for a second code instance. */
    259     return PDMCritSectEnterDebug(pCritSect, rcBusy, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     248    return pdmCritSectEnter(pCritSect, rcBusy, NULL);
     249#else
     250    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     251    return pdmCritSectEnter(pCritSect, rcBusy, &SrcPos);
    260252#endif
    261253}
     
    283275{
    284276#ifdef PDMCRITSECT_STRICT
    285     return pdmCritSectEnter(pCritSect, rcBusy, PDMCRITSECT_STRICT_POS_ARGS);
    286 #else
    287     /* No need for a second code instance. */
    288     return PDMCritSectEnter(pCritSect, rcBusy);
     277    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     278    return pdmCritSectEnter(pCritSect, rcBusy, &SrcPos);
     279#else
     280    return pdmCritSectEnter(pCritSect, rcBusy, NULL);
    289281#endif
    290282}
     
    301293 * @param   pCritSect   The critical section.
    302294 */
    303 static int pdmCritSectTryEnter(PPDMCRITSECT pCritSect, PDMCRITSECT_STRICT_POS_DECL)
     295static int pdmCritSectTryEnter(PPDMCRITSECT pCritSect, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    304296{
    305297    /*
     
    316308    /* Not owned ... */
    317309    if (ASMAtomicCmpXchgS32(&pCritSect->s.Core.cLockers, 0, -1))
    318         return pdmCritSectEnterFirst(pCritSect, hNativeSelf, PDMCRITSECT_STRICT_POS_ARGS);
     310        return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
    319311
    320312    /* ... or nested. */
     
    355347{
    356348#ifndef PDMCRITSECT_STRICT
    357     return pdmCritSectTryEnter(pCritSect, PDMCRITSECT_STRICT_POS_ARGS);
    358 #else
    359     /* No need for a second code instance. */
    360     return PDMCritSectTryEnterDebug(pCritSect, (uintptr_t)ASMReturnAddress(), RT_SRC_POS);
     349    return pdmCritSectTryEnter(pCritSect, NULL);
     350#else
     351    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_NORMAL_API();
     352    return pdmCritSectTryEnter(pCritSect, &SrcPos);
    361353#endif
    362354}
     
    383375{
    384376#ifdef PDMCRITSECT_STRICT
    385     return pdmCritSectTryEnter(pCritSect, PDMCRITSECT_STRICT_POS_ARGS);
    386 #else
    387     /* No need for a second code instance. */
    388     return PDMCritSectTryEnter(pCritSect);
     377    RTLOCKVALIDATORSRCPOS SrcPos = RTLOCKVALIDATORSRCPOS_INIT_DEBUG_API();
     378    return pdmCritSectTryEnter(pCritSect, &SrcPos);
     379#else
     380    return pdmCritSectTryEnter(pCritSect, NULL);
    389381#endif
    390382}
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