VirtualBox

Changeset 25491 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Dec 18, 2009 3:20:48 PM (15 years ago)
Author:
vboxsync
Message:

IPRT,PDMCritSect: Fixing critsect regression; contains under construction rw deadlock detection code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r25478 r25491  
    140140
    141141
    142 RTDECL(void) RTLockValidatorInit(PRTLOCKVALIDATORREC pRec, RTLOCKVALIDATORCLASS hClass,
    143                                  uint32_t uSubClass, const char *pszName, void *hLock)
     142RTDECL(void) RTLockValidatorRecInit(PRTLOCKVALIDATORREC pRec, RTLOCKVALIDATORCLASS hClass,
     143                                    uint32_t uSubClass, const char *pszName, void *hLock)
    144144{
    145145    pRec->u32Magic      = RTLOCKVALIDATORREC_MAGIC;
     
    167167
    168168
    169 RTDECL(int)  RTLockValidatorCreate(PRTLOCKVALIDATORREC *ppRec, RTLOCKVALIDATORCLASS hClass,
    170                                   uint32_t uSubClass, const char *pszName, void *pvLock)
     169RTDECL(int)  RTLockValidatorRecCreate(PRTLOCKVALIDATORREC *ppRec, RTLOCKVALIDATORCLASS hClass,
     170                                      uint32_t uSubClass, const char *pszName, void *pvLock)
    171171{
    172172    PRTLOCKVALIDATORREC pRec;
     
    175175        return VERR_NO_MEMORY;
    176176
    177     RTLockValidatorInit(pRec, hClass, uSubClass, pszName, pvLock);
     177    RTLockValidatorRecInit(pRec, hClass, uSubClass, pszName, pvLock);
    178178
    179179    return VINF_SUCCESS;
     
    181181
    182182
    183 RTDECL(void) RTLockValidatorDelete(PRTLOCKVALIDATORREC pRec)
     183RTDECL(void) RTLockValidatorRecDelete(PRTLOCKVALIDATORREC pRec)
    184184{
    185185    Assert(pRec->u32Magic == RTLOCKVALIDATORREC_MAGIC);
     
    195195
    196196
    197 RTDECL(void) RTLockValidatorDestroy(PRTLOCKVALIDATORREC *ppRec)
     197RTDECL(void) RTLockValidatorRecDestroy(PRTLOCKVALIDATORREC *ppRec)
    198198{
    199199    PRTLOCKVALIDATORREC pRec = *ppRec;
     
    201201    if (pRec)
    202202    {
    203         RTLockValidatorDelete(pRec);
     203        RTLockValidatorRecDelete(pRec);
    204204        RTMemFree(pRec);
    205205    }
     206}
     207
     208
     209RTDECL(void) RTLockValidatorSharedRecInit(PRTLOCKVALIDATORSHARED pRec, RTLOCKVALIDATORCLASS hClass,
     210                                          uint32_t uSubClass, const char *pszName, void *hLock)
     211{
     212    pRec->u32Magic      = RTLOCKVALIDATORSHARED_MAGIC;
     213    pRec->uSubClass     = uSubClass;
     214    pRec->hClass        = hClass;
     215    pRec->hLock         = hLock;
     216    pRec->pszName       = pszName;
     217
     218    /* the table */
     219    pRec->cEntries      = 0;
     220    pRec->iLastEntry    = 0;
     221    pRec->cAllocated    = 0;
     222    pRec->fReallocating = false;
     223    pRec->afPadding[0]  = false;
     224    pRec->afPadding[1]  = false;
     225    pRec->afPadding[2]  = false;
     226    pRec->papOwners     = NULL;
     227    pRec->u64Alignment  = UINT64_MAX;
     228}
     229
     230
     231RTDECL(void) RTLockValidatorSharedRecDelete(PRTLOCKVALIDATORSHARED pRec)
     232{
     233    Assert(pRec->u32Magic == RTLOCKVALIDATORSHARED_MAGIC);
     234
     235    /*
     236     * Flip it into table realloc mode and take the destruction lock.
     237     */
     238    rtLockValidatorSerializeDestructEnter();
     239
     240    if (!ASMAtomicCmpXchgBool(&pRec->fReallocating, true, false))
     241    {
     242        for (;;)
     243        {
     244            rtLockValidatorSerializeDestructEnter();
     245            rtLockValidatorSerializeDetectionEnter();
     246            rtLockValidatorSerializeDetectionLeave();
     247            rtLockValidatorSerializeDestructEnter();
     248            if (ASMAtomicCmpXchgBool(&pRec->fReallocating, true, false))
     249                break;
     250        }
     251    }
     252
     253    ASMAtomicWriteU32(&pRec->u32Magic, RTLOCKVALIDATORSHARED_MAGIC_DEAD);
     254    ASMAtomicUoWriteHandle(&pRec->hClass, NIL_RTLOCKVALIDATORCLASS);
     255    if (pRec->papOwners)
     256    {
     257        PRTLOCKVALIDATORSHAREDONE volatile *papOwners = pRec->papOwners;
     258        ASMAtomicUoWritePtr((void * volatile *)&pRec->papOwners, NULL);
     259        ASMAtomicUoWriteU32(&pRec->cAllocated, 0);
     260
     261        RTMemFree((void *)pRec->papOwners);
     262    }
     263    ASMAtomicWriteBool(&pRec->fReallocating, false);
     264
     265    rtLockValidatorSerializeDestructLeave();
    206266}
    207267
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