VirtualBox

Changeset 25622 in vbox


Ignore:
Timestamp:
Jan 3, 2010 1:56:34 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56313
Message:

tstRTLockValidator: testcase improvements.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/lockvalidator.h

    r25618 r25622  
    654654RTDECL(void *) RTLockValidatorQueryBlocking(RTTHREAD hThread);
    655655
     656/**
     657 * Checks if the thread is running in the lock validator after it has entered a
     658 * block state.
     659 *
     660 * @returns true if it is, false if it isn't.
     661 * @param   hThread     The thread in question.
     662 */
     663RTDECL(bool) RTLockValidatorIsBlockedThreadInValidator(RTTHREAD hThread);
    656664
    657665
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r25618 r25622  
    412412    Assert(pPerThread->cWriteLocks == 0);
    413413    Assert(pPerThread->cReadLocks == 0);
     414    Assert(pPerThread->fInValidator == false);
    414415}
    415416
     
    11661167    rtLockValidatorWriteRecUnionPtr(&pThreadSelf->LockValidator.pRec, pRecU);
    11671168    rtLockValidatorCopySrcPos(&pThreadSelf->LockValidator.SrcPos, pSrcPos);
     1169    ASMAtomicWriteBool(&pThreadSelf->LockValidator.fInValidator, true);
    11681170    rtThreadSetState(pThreadSelf, enmSleepState);
    11691171
     
    11741176     * isn't any other place to check for this.  semmutex-win.cpp for instance.
    11751177     */
     1178    int rc = VINF_SUCCESS;
    11761179    if (rtLockValidatorReadThreadHandle(&pRecU->Excl.hThread) == pThreadSelf)
    11771180    {
    1178         if (fRecursiveOk)
    1179             return VINF_SUCCESS;
    1180         rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU);
    1181         rtLockValidatorComplainPanic();
     1181        if (!fRecursiveOk)
     1182        {
     1183            rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU);
     1184            rtLockValidatorComplainPanic();
     1185            rc = VERR_SEM_LV_NESTED;
     1186        }
     1187    }
     1188    /*
     1189     * Perform deadlock detection.
     1190     */
     1191    else if (!rtLockValidatorIsSimpleNoDeadlockCase(pRecU))
     1192        rc = rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos);
     1193
     1194    if (RT_FAILURE(rc))
    11821195        rtThreadSetState(pThreadSelf, enmThreadState);
    1183         return VERR_SEM_LV_NESTED;
    1184     }
    1185 
    1186     /*
    1187      * Perform deadlock detection.
    1188      */
    1189     int rc = VINF_SUCCESS;
    1190     if (!rtLockValidatorIsSimpleNoDeadlockCase(pRecU))
    1191     {
    1192         rc = rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos);
    1193         if (RT_FAILURE(rc))
    1194             rtThreadSetState(pThreadSelf, enmThreadState);
    1195     }
     1196    ASMAtomicWriteBool(&pThreadSelf->LockValidator.fInValidator, false);
    11961197    return rc;
    11971198}
     
    13651366    rtLockValidatorWriteRecUnionPtr(&pThreadSelf->LockValidator.pRec, pRecU);
    13661367    rtLockValidatorCopySrcPos(&pThreadSelf->LockValidator.SrcPos, pSrcPos);
     1368    ASMAtomicWriteBool(&pThreadSelf->LockValidator.fInValidator, true);
    13671369    rtThreadSetState(pThreadSelf, enmSleepState);
    13681370
     
    13701372     * Don't do deadlock detection if we're recursing.
    13711373     */
     1374    int rc = VINF_SUCCESS;
    13721375    PRTLOCKVALRECSHRDOWN pEntry = rtLockValidatorRecSharedFindOwner(&pRecU->Shared, pThreadSelf, NULL);
    13731376    if (pEntry)
    13741377    {
    1375         if (fRecursiveOk)
    1376             return VINF_SUCCESS;
    1377         rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU);
    1378         rtLockValidatorComplainPanic();
     1378        if (!fRecursiveOk)
     1379        {
     1380            rtLockValidatorComplainFirst("Recursion not allowed", pSrcPos, pThreadSelf, pRecU);
     1381            rtLockValidatorComplainPanic();
     1382            rc =  VERR_SEM_LV_NESTED;
     1383        }
     1384    }
     1385    /*
     1386     * Perform deadlock detection.
     1387     */
     1388    else if (!rtLockValidatorIsSimpleNoDeadlockCase(pRecU))
     1389        rc = rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos);
     1390
     1391    if (RT_FAILURE(rc))
    13791392        rtThreadSetState(pThreadSelf, enmThreadState);
    1380         return VERR_SEM_LV_NESTED;
    1381     }
    1382 
    1383     /*
    1384      * Perform deadlock detection.
    1385      */
    1386     int rc = VINF_SUCCESS;
    1387     if (!rtLockValidatorIsSimpleNoDeadlockCase(pRecU))
    1388     {
    1389         rc = rtLockValidatorDeadlockDetection(pRecU, pThreadSelf, pSrcPos);
    1390         if (RT_FAILURE(rc))
    1391             rtThreadSetState(pThreadSelf, enmThreadState);
    1392     }
     1393    ASMAtomicWriteBool(&pThreadSelf->LockValidator.fInValidator, false);
    13931394    return rc;
    13941395}
     
    18601861
    18611862
     1863RTDECL(bool) RTLockValidatorIsBlockedThreadInValidator(RTTHREAD hThread)
     1864{
     1865    bool            fRet    = false;
     1866    PRTTHREADINT    pThread = rtThreadGet(hThread);
     1867    if (pThread)
     1868    {
     1869        fRet = ASMAtomicReadBool(&pThread->LockValidator.fInValidator);
     1870        rtThreadRelease(pThread);
     1871    }
     1872    return fRet;
     1873}
     1874RT_EXPORT_SYMBOL(RTLockValidatorIsBlockedThreadInValidator);
     1875
     1876
    18621877RTDECL(bool) RTLockValidatorSetEnabled(bool fEnabled)
    18631878{
  • trunk/src/VBox/Runtime/common/misc/thread.cpp

    r25618 r25622  
    13051305    Assert(RTTHREAD_IS_SLEEPING(enmState));
    13061306    PRTTHREADINT pThread = hThread;
    1307     if (hThread && rtThreadGetState(pThread) == RTTHREADSTATE_RUNNING)
     1307    if (pThread && rtThreadGetState(pThread) == RTTHREADSTATE_RUNNING)
    13081308        rtThreadSetState(pThread, enmState);
    13091309}
  • trunk/src/VBox/Runtime/include/internal/lockvalidator.h

    r25611 r25622  
    6565    /** Number of registered read locks that this thread owns, nesting included. */
    6666    int32_t volatile                cReadLocks;
     67    /** The thread is running inside the lock validator. */
     68    bool volatile                   fInValidator;
     69    /** Reserved for alignment purposes. */
     70    bool                            afReserved[3];
    6771    /** Bitmap indicating which entires are free (set) and allocated (clear). */
    6872    uint32_t                        bmFreeShrdOwners;
    69     /** Reserved for alignment purposes. */
    70     uint32_t                        u32Reserved;
    7173    /** Statically allocated shared owner records */
    7274    RTLOCKVALRECSHRDOWN             aShrdOwners[32];
  • trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp

    r25621 r25622  
    5353
    5454static uint32_t             g_cThreads;
    55 static uint32_t volatile    g_iDeadlockThread;
     55static uint32_t             g_iDeadlockThread;
    5656static RTTHREAD             g_ahThreads[32];
    5757static RTCRITSECT           g_aCritSects[32];
     
    128128            if (   enmState == enmDesiredState
    129129                && (   !pvLock
    130                     || pvLock == RTLockValidatorQueryBlocking(hThread)))
     130                    || (   pvLock == RTLockValidatorQueryBlocking(hThread)
     131                        && !RTLockValidatorIsBlockedThreadInValidator(hThread) )
     132                   )
     133               )
    131134                return true;
    132135        }
    133         else if (enmState != RTTHREADSTATE_RUNNING)
     136        else if (   enmState != RTTHREADSTATE_RUNNING
     137                 && enmState != RTTHREADSTATE_INITIALIZING)
    134138            return false;
    135139        RTThreadSleep(g_fDoNotSpin ? 3600*1000 : iLoop > 256 ? 1 : 0);
     
    173177        }
    174178    }
     179    RTThreadSleep(4);                   /* fudge factor */
    175180    return VINF_SUCCESS;
    176181}
     
    416421    for (uint32_t iPass = 0; iPass < cPasses && RTTestErrorCount(g_hTest) == cErrors; iPass++)
    417422    {
    418 #if 0 /** @todo figure why this ain't working for either of the two tests! */
    419423        g_iDeadlockThread = (cThreads - 1 + iPass) % cThreads;
    420 #endif
    421424        g_cLoops = 0;
    422425        g_cDeadlocks = 0;
     
    493496}
    494497
     498
    495499int main()
    496500{
     
    516520     */
    517521    test1(3, 1);
    518 
    519522    test2(1, 1);
    520523    test2(3, 1);
     
    525528    RTLockValidatorSetQuiet(true);
    526529
    527     test1( 2, 1024);
    528     test1( 3, 1024);
    529     test1( 7,  896);
    530     test1(10,  768);
    531     test1(15,  512);
    532     test1(30,  384);
    533 
    534     test2( 1,  100);
    535     test2( 2, 1024);
    536     test2( 3, 1024);
    537     test2( 7,  896);
    538     test2(10,  768);
    539     test2(15,  512);
    540     test2(30,  384);
     530    test1( 2, 256);                     /* 256 * 4ms = 1s (approx); 4ms == fudge factor */
     531    test1( 3, 256);
     532    test1( 7, 256);
     533    test1(10, 256);
     534    test1(15, 256);
     535    test1(30, 256);
     536
     537    test2( 1, 256);
     538    test2( 2, 256);
     539    test2( 3, 256);
     540    test2( 7, 256);
     541    test2(10, 256);
     542    test2(15, 256);
     543    test2(30, 256);
    541544
    542545    test3( 2,  1,  2);
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